Monday, 4 January 2016

XML : how to send xml to web service with php

I use RESTful webservice and it's show some xml.

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>   - <users>  -    <user>          <id>1</id>           <name>Mahesh</name>           <profession>Teacher</profession>         </user>    </users>    

I want to add new xml, send to the webservice.

  $xml =       '<users>          <user>            <id>3</id>            <name>hangga</name>            <profession>IT</profession>          </user>       </users>';    

Here my php code :

  $curl = curl_init();  curl_setopt($curl, CURLOPT_URL, "http://localhost:18080/UserManagement/rest/UserService/users");  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); //setting content type header  curl_setopt($curl, CURLOPT_POST, $xml);//Setting raw post data as xml  $result = curl_exec($curl);  curl_close($curl);  print($result);    

But nothing happens, web service not show new XML. My question how to add new xml and send it to web service using php? should I use cUrl? is there another way? I really need help, the answer will very appreciated. Thanks all

No comments:

Post a Comment