Curl学习笔记

Posted on July 5, 2013
  1. 只展示正文

     curl www.sina.com
    
  2. -o/–output [file]

    Write output to file instead of stdout 保存到本地

     curl -o [filename] www.sina.com
    
  3. -L/–location

    Follow Location 自动跳转

     curl -L www.sina.com
    
  4. -i/–include

    Include protocol headers in the output 展示包括响应头

     curl -i www.sina.com
    
  5. -I/–head

    Show document info only 只展示headers

     curl -I www.sina.com
    
  6. -v/–verbose

    Make the operation more talkative 可以显示一次http通信的整个过程,包括端口连接和http request头信息

     curl -v www.sina.com
    
  7. -d/–data [data]

    HTTP POST data 使用post发送数据

     curl -d content=123 -d contact=abc hr.tuxx800.com/messages
    
     curl -d content=123 -data 'a=1&b=2' hr.tuxx800.com/messages
    

    如果你的数据没有经过表单编码,还可以让curl为你编码,参数是--data-urlencode

     curl --data-urlencode 'content=123 sds' -d contact=abc hr.tuxx800.com/messages 
    
  8. -X/–request [command]

    Specify request command to use 指定http动词,默认是GET

     curl -X PUT www.example.com   
    
     curl -X POST www.example.com   
    
  9. -F/–form [name=content]

    Specify HTTP multipart POST data 使用enctype=’multipart/form-data’表单提交数据

     curl -F [email protected]/tmp/image.jpg -F content=hello http://www.example.com/abc
    
  10. -e/–referer

    Referer URL 指定referer

    curl --referer http://www.example.com http://www.example.com/abc
    
  11. -A/–user-agent [string]

    User-Agent to send to server

  12. -b/–cookie [name=string/file]

    Cookie string or file to read cookies from 附加cookie

    TODO 设置多个

  13. -H/–header [line]

    Custom header to pass to server 添加header

    curl -H 'Host: www.sina.com'  http://192.168.100.99/abc
    
  14. -u/–user [user[:password]]

    Set server user and password 设置http认证

    curl --user name:password example.com
    
  15. get 发送json body

curl -v -H 'Content-Type: application/json' -X GET -d '{"Uin":"123"}' 'http://127.0.0.1:9911/user_flows'