简体   繁体   English

curl POST请求不起作用

[英]curl POST request is not working

I am trying to consume POST URL using curl. 我正在尝试使用curl使用POST URL。 Curl request is as below: 卷曲请求如下:

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

Although JSON data is accurate I am getting bad request error. 尽管JSON数据准确无误,但我收到了错误的请求错误。

Response is as below: 响应如下:

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

Your have set Content-Type as application/x-www-form-urlencoded so you have to send form URL encoded data : 您已将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

which gives : 这使 :

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

Moreover, it seems your endpoint doesn't support JSON, when issuing your previous request with Content-Type: application/json it gives : 而且,似乎您的端点不支持JSON,当使用Content-Type: application/json发出先前的请求时,它会给出:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM