【问题标题】:curl POST request is not workingcurl POST 请求不起作用
【发布时间】:2017-02-27 10:19:09
【问题描述】:

我正在尝试使用 curl 使用 POST URL。卷曲请求如下:

curl -k -H "Content-Type    : application/x-www-form-urlencoded;charset=UTF-8" -H "Accept: application/json, text/plain, */*" -H "Authorization : OAuth oauth_consumer_key=2IaG9fzswU1f8bJ2bWCIIQ" -X POST -d "{'consumer_id':'google_bps','app_id':'google_bps_app','user_id':'bala.gto3','first_name':'bala','last_name':'gto3','email':'bala.gto3@gmail.com'}" https://ec2-54-189-116-121.us-west-2.compute.amazonaws.com/cec_baseline/api/users/save

虽然 JSON 数据是准确的,但我收到了错误的请求错误。

回复如下:

{"status":400,"code":0,"message":"Bad Parameters: Consumer Id and Application Id Mandatory!","description":"BAD REQUEST","result":[]}

【问题讨论】:

    标签: rest curl post


    【解决方案1】:

    您已将 Content-Type 设置为 application/x-www-form-urlencoded,因此您必须发送表单 URL 编码数据:

    curl -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
            -H "Accept: application/json, text/plain, */*" \
            -H "Authorization: OAuth oauth_consumer_key=2IaG9fzswU1f8bJ2bWCIIQ" \
            -X POST \
            -d 'consumer_id=google_bps&app_id=google_bps_app&user_id=bala.gto3&first_name=bala&last_name=gto3&email=bala.gto3@gmail.com' \
            https://ec2-54-189-116-121.us-west-2.compute.amazonaws.com/cec_baseline/api/users/save
    

    给出:

    {"status":200,"code":1,"message":"Successfully Saved!","description":"","result":[]}
    

    此外,您的端点似乎不支持 JSON,当您使用 Content-Type: application/json 发出您之前的请求时,它会给出:

    {"status":400,"code":0,"message":"Content Type must be application\/x-www-form-urlencoded!","description":"BAD REQUEST","result":[]}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2023-04-06
      相关资源
      最近更新 更多