How PHP sends XML messages

Source: Internet
Author: User
How PHP sends XML messages

POST http/1.0
User-agent:
Content-type:application/x-fox
content-length:nnnn
  
  
  
...
  


Now to send the XML data in the format above, try curl but not successful, everybody help


------Solution--------------------
Curl is possible, but the parameter settings are cumbersome. This situation has some out-of-the-box class library implementations that provide a simple example

 
  
if ($_server[' request_method ' = = = = ' POST ') {
Receive
$content = file_get_contents (' php://input ');
$xml = simplexml_load_string ($content);
echo "Response from the XML receiver \ n";
Print_r (Get_object_vars ($xml));
Exit
}

Send 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;

To illustrate your HTTP request example, the request content entity and header need to be separated by two groups \ r \ n. In addition, your XML file format is incorrect, and the tag attribute also contains the full-width 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.