簡體   English   中英

通過php發送XML並返回響應

[英]Sending XML via php and getting back a response

我在通過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);

?>

當您輸入“剛返回空白頁面”時,您是在輸入網址時指的是Web瀏覽器的響應嗎? 如果這是您所指的,那么您正在使用哪種Web瀏覽器? 我建議您嘗試使用其他Web瀏覽器(Safari,FireFox,Chrome),然后查看獲得的結果。

為什么使用標頭設置POST方法並進行自定義請求? Curl完全有能力按原樣執行POST:

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

自定義請求是針對您想要執行不太常見的方法(例如HEAD或PUT請求)的。

和PHP具有SoapClient類來處理SOAP協議。 朋友,您確定要手寫嗎? :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM