开发者

Bad request error when posting xml using curl

Am pulling my hair out trying to solve this problem, am getting a bad request error when posting to XML using curl. My code is:

$post_string = '<XML DATA>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,
            array('Content-Type: text/xml; charset=utf-8', 'SOAPAction: ""'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);

var_dump($data);

Any ideas on what's wrong?

Below is my xml string

   <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SubmitLead xmlns="">
<xmlLead>
<Lead>
<General>
<dealer type="CMH">273</dealer>
<source  ref="stockid">3256</source>
<enquiry></enquiry>
<subtype></subtype>
<comment></comment>
</General>
<Prospect>
<title>n.a</title>
<name>j</name>
<surname>m</surname>
<email>开发者_如何学运维jm@test.com</email>
<home>home</home>
<work>n.a</work>
<mobile>4545</mobile>
<idnumber>n.a</idnumber>
 <comment>4545</comment>
 <area>n.a</area>
</Prospect>
<Item>
 <id>25DLC61717</id>
 <makeAsked></makeAsked>
 <modelAsked></modelAsked>
 <yearAsked></yearAsked>
 <mileageAsked></mileageAsked>
 <priceAsked></priceAsked>
 <colourAsked></colourAsked/>
 <registration></registration>
 <vin></vin>
 <purchaseDate/></purchaseDate>
 </Item>
 </Lead>
 </xmlLead>
 </SubmitLead>
 </soap:Body>
 </soap:Envelope>


probably a bad request because the XML is not valid XML ?


in my ruby code I did that way

 resp = http.post("/soap/service", xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8', 'SOAPAction' => "/soap/service/Request" })

and it works

so difference is only in headers

also maybe you should use secure connection if url has https scheme?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜