I am new in php programming and I would like to add data to my http request in xml format. I use curl to generate HTTP request using this PHP code :
<?php
$fields = array( 'SERIAL_NUMBER ' => urlencode('123456'),
'HARDWARE_ID ' => urlencode('455FFG'),
'CODE ' => urlencode('99'),
//field goes here
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init("http://192.168.1.110:10000");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
I would like to add fields array [ SERIAL_NUMBER and HARDWARE_ID and CODE ] as data in http request in format xml
the format of the desired http request is :
POST / HTTP/1.1
Host: 192.168.1.110:10000
Accept: */*
Content-Length: 52
Content-Type: application/x-www-form-urlencoded
HTTP/1.1 100 Continue //server responce
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Device Parameters>
<SERIAL_NUMBER>123456</SERIAL_NUMBER>
<HARDWARE_ID>455FFG</HARDWARE_ID>
<CODE>99</CODE>
</Device Parameters>
Note : my server listen to port 10000 @ 192.168.1.110
any help is appreciated
You can use SimpleXMLElement. Represents an element in an XML document.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.