美文网首页linux操作系统Nodejs、ExpressJs
CURL命令模拟Http Get/Post请求

CURL命令模拟Http Get/Post请求

作者: 刀刀天涯 | 来源:发表于2016-05-30 16:46 被阅读44243次

    在对后端程序进行测试的时候,需要进行模拟连接或者书写测试脚本.

    curl是一个很棒的命令.

    例如目标网站Url:
    127.0.0.1:8080/check_your_status?user=Summer&passwd=12345678
    通过Get方法请求:
    curl protocol://address:port/url?args
    curl http://127.0.0.1:8080/check_your_status?user=Summer&passwd=12345678
    通过Post方法请求:
    curl -d "args" "protocol://address:port/url"
    curl -d "user=Summer&passwd=12345678" "http://127.0.0.1:8080/check_your_status"
    这种方法是参数直接在header里面的
    如需将输出指定到文件可以通过重定向进行操作.
    curl -H "Content-Type:application/json" -X POST --data (json.data) URL
    curl -H "Content-Type:application/json" -X POST --data '{"message": "sunshine"}' http://localhost:8000/
    这种方法是json数据直接在body里面的

    curl 命令若还未安装可以通过以下命令进行安装:

    ubuntu:  
    $ sudo apt-get install curl
    centos:
    $ sudo yum install curl 
    

    curl作为一个很强大的命令,本文只介绍了一点内容,更多关于curl命令介绍参照man
    或者参考:http://man.linuxde.net/curl

    仅作分享,不喜勿喷.

    相关文章

      网友评论

      本文标题:CURL命令模拟Http Get/Post请求

      本文链接:https://www.haomeiwen.com/subject/pgqcdttx.html