如何用php将xml发送到web服务
我使用RESTfulWebService,它显示了一些xml如何用php将xml发送到web服务,php,xml,web-services,curl,Php,Xml,Web Services,Curl,我使用RESTfulWebService,它显示了一些xml <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <users> - <user> <id>1</id> <name>Mahesh</name> <profession>Teacher</professi
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <users>
- <user>
<id>1</id>
<name>Mahesh</name>
<profession>Teacher</profession>
</user>
</users>
但什么也没发生,web服务没有显示新的XML。我的问题是如何添加新的xml并使用php将其发送到web服务?我应该用卷发吗?还有别的办法吗?我真的需要帮助,答案将非常感谢。谢谢大家您应该使用在curl请求中发送的新xml更新服务中的数据,这样当您执行RESTful Web服务时,您将获得更新的数据。因此,我必须在RESTful中创建一些函数代码来获取php代码?我的意思是,发布您的数据,您获得它,然后处理它,然后显示它。您在UserService/users中做了什么?HTTP状态415-不受支持的媒体类型是什么意思?您应该使用在curl请求中发送的新xml更新服务中的数据,因此,当您使用RESTful Web服务时,您将获得更新的数据。因此,我必须在RESTful中创建一些函数代码来获取php代码?我的意思是,发布数据,获取数据,处理数据,然后显示数据。您在用户服务/用户中做了什么?HTTP状态415-不受支持的媒体类型是什么意思?
$url = 'http://webservice/example/user';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responses = curl_exec($ch);
curl_close($ch);
$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);
$url = 'http://webservice/example/user';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responses = curl_exec($ch);
curl_close($ch);