

The cURL is also used in command lines or scripts for data transfer.
Php curl json response code#
I tried many ways to format the XML result as needed without luck. The cURL facilitates the way that can hit a URL from our code to get an HTML response from it.

I've heard / read some stuff about needing to add an HTTPHEADER option, which I have tried doing in the following manner: curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')) īut when I tried this I just got an error from the external site that I'm POST-ing to.īelow is my entire function. I need to output an array with a specif format from a cURL request. php curl Response is including the HTTP Header in a JSON response.

$ch = curl_init() Ĭurl_setopt( $ch, CURLOPT_URL, $flickr_upload ) Ĭurl_setopt( $ch, CURLOPT_POSTFIELDS, $parameters_string ) You can refer to this page for documentation on all of PHPs cURL functions. (Ergnis is null) My approach: curlsetopt ( ch, CURLOPTHEADER, 0. HTTP/1.1 400 Bad Request Cache-Control: no-cache Pragma: no-cache Content-Type: application/json charsetutf-8 Expires: -1 Server: Microsoft-IIS/8.5 Date: Sun, 17:47:34 GMT Content-Length: 38 Are the headers returned by the cURL request. That's why this non jsondecode can be converted into an Object / Array. Ive got a simple PHP script that sends an HTTP POST request via cURL, and expects a json string in response (would have loved to use an existing library like peclhttp/HTTPRequest for this, but cant). Thus, response is no longer a pure JSON string. but I can't use that data to continue on.īelow is what I've got so far. For all who, as I have been looking for a solution: curlsetopt ( ch, CURLOPTHEADER, 1) : Causes header information to be contained in response. I'm currently trying to use a cURL method to POST data to an external server and need it to return data in json formatted code, right now the only format it returns in is xml.
