My code like that as below, but I cannot get the response successfully. Is anything wrong with my code?
Code:
$headers = array('Content-Type: text/xml;charset=UTF-8','Content-Encoding: gzip',);
$gziped_xml_content = gzencode($xml_content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $the_web_service_url);
curl_setopt($ch, CURLOPT_TIMEOUT,120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_POSTFIELDS, $gziped_xml_content);
$res = curl_exec($ch);
curl_close($ch);
The code is correct. I mean the curl is ok. The error is elsewhere. Your code returns following
verbose
output which implies the code is correct.Scenario#1: It can be the server can not handle gzip data. So its throwing you error.
Scenario#2: May be the XML you are sending that has incorrect format, and server failed to parse it and throw you error.
Scenario#3: May be the data you are sending its too large(content length > 1024) for a normal curl post. That case you have to use
multipart/form-data
form posting.But before anything, run the curl code with VERBOSE mode enable and it will help you to debug this yourself.
Finally,
I cannot get the response successfully
is not a good point to make in your question. Rather using the error you are getting along with more problematic info will help the others who want to help you!