且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP SOAP HTTP请求

更新时间:2022-03-26 06:08:40

您有两种选择!您可以使用soap对象创建请求,该请求基于WSDL将知道与远程服务器进行通信的正确方法.您可以在 PHP手册中查看如何执行此操作.

You have a couple of options! You could use soap objects to create the request which, based upon a WSDL will know the correct way to talk to the remote server. You can see how to do this at the PHP manual.

或者,您可以使用CURL来完成工作.您需要知道将数据发布到何处(如上例所示),然后您可以执行以下操作:

Alternatively, you can use CURL to do the work. You'll need to know where to post the data to (which it looks like is in the example above), then you can just do something like this:

$curlData = "<?xml version="1.0" encoding="utf-8"?>... etc";
$url='http://wherever.com/service/';
$curl = curl_init();

curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_ENCODING,'gzip');

curl_setopt($curl,CURLOPT_HTTPHEADER,array (
    'SOAPAction:""',
    'Content-Type: text/xml; charset=utf-8',
));

curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

$result = curl_exec($curl);
curl_close ($curl);

然后您应该将结果保存到$ result变量中.然后,您可以尝试将其转换为XML文档,尽管有时由于编码我发现它不起作用:

You then should have the result in the $result var. You can then try to convert it to an XML doc, although sometimes I've found due to encoding this doesn't work:

$xml = new SimpleXMLElement($result);
print_r($xml);