php curl class, Sending Curl request with Content Type json -


i need send json post request url. using php curl class. request header showing content type application/x-www-form-urlencoded if have set content type. here code

 $curl1 = new curl();  $curl1->setopt(curlopt_returntransfer, true); $curl1->setopt(curlopt_header, false); $curl1->setopt(curlopt_post, true); $curl1->setopt(curlopt_postfields, $data);  $curl1->setopt(curlopt_httpheader, array(     "content-type:application/json"  )); $curl1->setbasicauthentication('username', 'password');  $curl1->post('https://example.com/url'); 

i getting 500 error api. have contacted them, said content type isn't right. have print out content type looks like

caseinsensitivearray object ( [container:curl\caseinsensitivearray:private] => array     (         [request-line] => post /url http/1.1         [authorization] => basic yccx4mza1ztu0mdkwnda3ogi1owi4yjuynji4mjjjntm6mtddfhf7755y1zdq0ndvmy2i2ntezzjllntu3mzi4mtm=         [user-agent] => php-curl-class/3.4.5 (+https://github.com/php-curl-class/php-curl-class) php/5.5.24 curl/7.36.0         [host] => ssapi.shipstation.com         [accept] => */*         [content-type] => application/x-www-form-urlencoded     )  ) 

please check content type in request headers , in code. different. setting content-type: applicaiton/json why in request showing application/x-www-form-urlencoded?

and here json sending

 {"ordernumber":"benorder","orderdate":"2015-05-31t03:38:36-0700","orderstatus":"awaiting_shipment","billto":{"name":"stack yu","company":null,"street1":" stockton avenue","city":"plainfield","state":"il","postalcode":"44444"},"shipto":{"name":"stack yu","company":null,"street1":" stockton avenue","city":"plainfield","state":"il","postalcode":"44444"},"items":[{"sku":"s102","name":"my prodcut","quantity":"1"}]} 

any appreciated!

php-curl-class has separate method setting header, check the documentation. so, have use:

$curl1->setheader("content-type", "application/json"); 

and content-type header set.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -