Home > php教程 > php手册 > body text

PHP实现Soap通讯的方法,phpsoap通讯

WBOY
Release: 2016-06-13 09:22:24
Original
1009 people have browsed it

PHP实现Soap通讯的方法,phpsoap通讯

本文实例讲述了PHP实现Soap通讯的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:

function HttpSoap($server, $port, $url, $namespace, $action, $data) {
$fp = @fsockopen($server, $port);
if (!$fp) {
return FALSE;
} else {
$soapData = ConstructData($namespace, $action, $data);
$length = strlen($soapData);
$out = "POST $url HTTP/1.1\r\n";
$out .= "Host: $server\r\n";
$out .= "Content-Type: text/xml; charset=utf-8\r\n";
$out .= "Content-Length: $length\r\n";
$out .= "SOAPAction: \"$namespace$action\"\r\n\r\n";
$out .= $soapData;
$out .= "\r\n\r\n";
fputs($fp, $out);
stream_set_timeout($fp, 2);
$header = "";
while($line = trim(fgets($fp))) {
$header .= $line."\n";
}
$dataPos = strpos($header, "Content-Length: ") + 16;
$dataEnd = strpos($header, "\n", $dataPos);
$dataLength = substr($header, $dataPos, $dataEnd - $dataPos);
$data = "";
if($dataLength > 0) {
$data = fread($fp, $dataLength);
}
fclose($fp);
if(strlen($data) != $dataLength || $dataLength return FALSE;
}
return $data;
}
}
function ConstructData($namespace, $action, $data) {
$soapData = "

\r\n";
$soapData .= "http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
$soapData .= " \r\n";
$soapData .= " \r\n";
foreach($data as $name => $value) {
$name = iconv("GBK","UTF-8",$name);
$value= iconv("GBK","UTF-8",$value);
$soapData .= " $value$name>\r\n";
}
$soapData .= " $action>\r\n";
$soapData .= " \r\n";
$soapData .= "
";
return $soapData;
}
$data=array(
'user'=>'测试', //如果需要输入二进制数据请采用BASE64编码
'pass'=>'test'
);
echo HttpSoap('sample.anyhost.com', 80, '/sampleSoap.asmx', 'http://tempuri.org/', 'logIn', $data);
?>

希望本文所述对大家的PHP程序设计有所帮助。

问在PHP采用SOAP方式调用,在那里更改把delphi自动生成的:ioLiteral与ioDocument

在你导入XML时生成的接口文件里面的文件尾部
 

php怎通过soap方式与delphi通信

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template