How php sends xml messages & nbsp; POST & nbsp; & lt; URL & gt; & nbsp; HTTP/1.0USER-Agent: & nbsp; & lt; client & nbsp; Application & nbsp; Name & gt; Content-Type: & nbs php how to send xml packets
POST
HTTP/1.0
USER-Agent:
Content-Type: application/x-fox
Content-Length: nnnn
...
Now I want to send xml data in the above format. I tried curl but it was not successful. please help me.
------ Solution --------------------
CURL is acceptable, but it is troublesome to set parameters. In this case, some ready-made class libraries are implemented to provide a simple example.
If ($ _ SERVER ['request _ method'] = 'post '){
// Receive
$ Content = file_get_contents ('php: // input ');
$ Xml = simplexml_load_string ($ content );
Echo "response from XML receiver \ n ";
Print_r (get_object_vars ($ xml ));
Exit;
}
// Sending behavior
$ Xml = <
World
Xml;
$ Setting = array (
'Http' => array (
'Method' => 'post ',
'User _ agent' =>'
',
'Header' => "Content-type: application/x-www-form-urlencoded ",
'Content' => $ xml
)
);
$ Context = stream_context_create ($ setting );
$ Url = 'http: // localhost/'. $ _ SERVER ['request _ URI'];
$ Response = file_get_contents ($ url, null, $ context );
Echo $ response;
In your HTTP request example, the request content entity and header must be separated by two groups of \ r \ n. In addition, the format of your XML file is incorrect, and the tag attribute also contains the fullwidth symbol.