curl POST请求无效

时间:2017-02-27 10:19:09

标签: rest curl post

我正在尝试使用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":[]}

1 个答案:

答案 0 :(得分:1)

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

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":[]}