我在通过PHP发送以下XML时遇到问题。我似乎无法让脚本正确,它只是返回一个空白页面。任何建议都会很棒。我似乎没有出现任何错误。
POST /PubServices/WebServices/PublicationWebServices.asmx HTTP/1.1
Host: www.geminifund.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
POST /PubServices/WebServices/PublicationWebServices.asmx HTTP/1.1
Host: www.geminifund.com
Content-Type: application/soap+xml; charset= utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetHistroricalNav xmlns="http://www.geminifund.com/webservices/">
<startDate>dateTime</startDate>
<endDate>dateTime</endDate>
<portfolio>string</portfolio>
</GetHistroricalNav>
</soap12:Body>
</soap12:Envelope>
我的脚本如下
<?php
$url = "http://www.geminifund.com";
$post_string = '<?xml version="1.0" encoding="UTF-8"?>
<rootNode>
<innerNode>
<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>
<GetHistroricalNav xmlns="http://www.geminifund.com/webservices/">
<startDate>2011-06-30</startDate>
<endDate>2011-7-30</endDate>
<portfolio>1778/portfolio>
</GetHistroricalNav>
</soap:Body>
</soap:Envelope>
</innerNode>
</rootNode>';
$header = "POST /PubServices/WebServices/PublicationWebServices.asmx HTTP/1.1 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n";
$header .= $post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch);
if(curl_errno($ch))
print curl_error($ch);
else
curl_close($ch);
?>
答案 0 :(得分:0)
当你写“它刚回来时有一个空白页面”你是指你输入网址时的网页浏览器响应吗?如果这是您所指的,您使用的是哪种Web浏览器?我建议你尝试不同的网络浏览器(Safari,FireFox,Chrome),看看你得到了什么结果。
答案 1 :(得分:0)
为什么使用标头设置POST方法并执行自定义请求? Curl完全有能力按原样执行POST:
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
自定义请求适用于您想要执行不常用的方法,例如HEAD或PUT请求。
答案 2 :(得分:0)
和PHP有SoapClient类来处理SOAP协议。朋友,你确定要用手写的方式做吗? :)