zoukankan      html  css  js  c++  java
  • curl post传递json数据

    有时想在命令行使用post

    http提交一个表单,比较常用的是POST模式和GET模式

    GET模式什么option都不用,只需要把变量写在url里面就可以了

    比如:curl http://www.waynerQiu.com/login.cgi?user=nickwolfe&password=12345

    而POST模式的option则是 -d (--data

    -d/--data <data>
    (HTTP) Sends the specified data in a POST request to the HTTP
    server, in the same way that a browser does when a user has filled
    in an HTML form and presses the submit button. This will cause curl
    to pass the data to the server using the content-type >application/x-
    www-form-urlencoded.

    比如,curl -d "user=nickwolfe&password=12345" http://www.waynerQiu.com/login.cgi

    就相当于向这个站点发出一次登陆申请;

    到底该用GET模式还是POST模式,要看对面服务器的程序设定。

    curl --data "data=xxx" example.com/form.cgi

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

      curl --data-urlencode "date=April 1" example.com/form.cgi

    一点需要注意的是,POST模式的文件上传,比如

    <form method="POST" enctype="multipar/form-data" 

    action="http://... /~zzh/up_file.cgi">

    <input type=file name=upload>

    <input type=submit name=nick value="go">

    </form>

    这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:

    curl -F upload=@localfile -F nick=go http://.../~zzh/up_file.cgi

    11)https的时候使用本地证书,可以使用option:-E

    curl -E localcert.pem https://remote_server

    更多:

    http://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest

    http://www.dewen.org/q/3803/%E5%9C%A8linux%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%8Bcurl+%E6%8F%90%E4%BA%A4json%E6%95%B0%E6%8D%AE%E7%9A%84%E9%97%AE%E9%A2%98

  • 相关阅读:
    《剑指offer》Q01-12 (牛客10.11)
    北京,我来了
    pods的好处
    iOS那些你从未使用过的属性方法
    重构一个运行超过10年的老项目
    C#泛型
    认真思考创建对象的几种方式
    2014年终总结
    前端优化:AMDclean去除requirejs
    webstorm常用快捷键及插件
  • 原文地址:https://www.cnblogs.com/youxin/p/3628075.html
Copyright © 2011-2022 走看看