2017-02-27 189 views
0

我想使用curl來使用POST URL。捲曲請求如下:curl POST請求不起作用

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

你已經設置Content-Typeapplication/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 protected]' \ 
     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":[]} 

而且,似乎你的端點在發佈你的previou時不支持JSON請給Content-Type: application/json它給出:

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