我试图解决这个问题,但是在使用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>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>
答案 0 :(得分:0)
可能是一个糟糕的请求,因为XML不是有效的XML?
答案 1 :(得分:0)
在我的ruby代码中我这样做了
resp = http.post("/soap/service", xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8', 'SOAPAction' => "/soap/service/Request" })
并且有效
所以差异仅在标题
中 如果url有https方案,也可以使用安全连接吗?