2012-07-25 56 views
0

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

所以我们需要做任何休息方法(无梨)发布xml请求。

有谁知道吗?

回答

0
wget http://example.com/path/to/interface 

或者在PHP中你可以使用常见的文件 - /流功能

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

使用cURL任何POST数据到任何API,并从服务器接收响应(也可以是XML, JSON,无论如何)。

要编写需要POST的XML请求,请使用SimpleXML并将其插入到您的API请求的POSTFIELD中。

看看这个答案,它与你的类似,但有一个区别。

https://stackoverflow.com/a/11638765/1548719

要发送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