2011-09-02 119 views
0

我正试图解决这个问题,因为在使用curl发布到XML时出现错误的请求错误。我的代码是:使用curl发布xml时出现错误的请求错误

$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); 

有什么不对?

下面是我的XML字符串

<?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>[email protected]</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> 

回答

0

可能是一个坏请求,因为XML不是有效的XML?

+0

已经测试了soapclient.com上的xml,它没问题。有一些与标题和IIS拒绝标头出于某种原因,不知道为什么 –

0

在我的Ruby代码我没有这样

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

和它的作品

所以差别只在头

也或许你应该使用安全连接,如果URL具有HTTPS方案?

相关问题