PHP implements the Soap communication method and phpsoap communication. PHP implements Soap communication. phpsoap communication this article describes how PHP implements Soap communication. Share it with you for your reference. The specific implementation method is as follows: Copy the code as follows: PHP implements the Soap communication method and phpsoap communication
This example describes how PHP implements Soap communication. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
<? Php
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 ";
$ Out. = $ soapData;
$ Out. = "\ 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 <= 0 ){
Return FALSE;
}
Return $ data;
}
}
Function ConstructData ($ namespace, $ action, $ data ){
$ SoapData ="
<? Xml version = "1.0 \" encoding = \ "UTF-8 \"?>
\ R \ n ";
$ SoapData. =" Http://schemas.xmlsoap.org/soap/envelope/\ "> \ r \ n ";
$ SoapData. =" \ R \ n ";
$ SoapData. = "<$ action xmlns = \" $ namespace \ "> \ r \ n ";
Foreach ($ data as $ name => $ value ){
$ Name = iconv ("GBK", "UTF-8", $ name );
$ Value = iconv ("GBK", "UTF-8", $ value );
$ SoapData. = "<$ name> $ value \ R \ n ";
}
$ SoapData. =" \ R \ n ";
$ SoapData. =" \ R \ n ";
$ SoapData. =" ";
Return $ soapData;
}
<?
$ Data = array (
'User' => 'test', // If you need to input binary data, use BASE64 encoding.
'Pass' => 'test'
);
Echo HttpSoap ('sample .anyhost.com ', 80,'/sampleSoap. asmx ', 'http: // tempuri.org/', 'login', $ data );
?>
I hope this article will help you with PHP programming.
In PHP, you can use the SOAP method to call the API. in this case, the automatically generated API named "ioLiteral" and "ioDocument" is changed.
The end of the file in the interface file generated when you import XML
How does php communicate with delphi through soap?
The example in this article describes how PHP implements Soap communication. Share it with you for your reference. The specific implementation method is as follows: the code is as follows...