0

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

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

有人知道吗?

4

2 回答 2

1

使用 cURL 将任何数据发布到任何 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
于 2012-07-25T07:01:08.600 回答
0
wget http://example.com/path/to/interface

或者在 PHP 中,您可以只使用常见的文件/流函数

file_get_contents('http://example.com/path/to/interface');
于 2012-07-25T06:31:19.760 回答