Php 没有pear的rest服务器

Php 没有pear的rest服务器,php,xml,Php,Xml,我们有一个php网站,我们正在尝试实现一个api。为了实现这个API,我们需要使用RESTFUL服务发送一个xml请求 因此,我们需要使用任何rest方法(不使用pear)来发布xml请求 有人知道吗 wget http://example.com/path/to/interface 或者在PHP中,您可以只使用通用的file-/stream函数 file_get_contents('http://example.com/path/to/interface'); 使用cURL将任何数据发布到

我们有一个php网站,我们正在尝试实现一个api。为了实现这个API,我们需要使用RESTFUL服务发送一个xml请求

因此,我们需要使用任何rest方法(不使用pear)来发布xml请求

有人知道吗

wget http://example.com/path/to/interface
或者在PHP中,您可以只使用通用的file-/stream函数

file_get_contents('http://example.com/path/to/interface');

使用cURL将任何数据发布到任何API,并从服务器接收响应(可以是XML、JSON等)

要编写需要发布的XML请求,请使用
SimpleXML
,并将其插入到API请求的POST字段中

看看这个答案,它与你的答案相似,但有一点不同

要向URL(API)发送帖子,您需要添加几个
CURLOPT
选项:

curl_setopt($ch, CURLOPT_POST, 1); // using usual POST (like form submitted application/x-www-form-urlencoded)
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); // defining content type of the request we are sending
curl_setopt($ch, CURLOPT_POSTFIELDS, $previouslyComposedXMLRequest); // and finally transmitting POST parameter in form of XML