How does php send xml packets?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.