2011-09-02 152 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方案?

相關問題