PHP:如何使用 XML 数据发送 REST 请求

标签 php xml rest request

我需要在 PHP 中使用 REST(POST 方法)向 API 发出请求。

但是数据需要是XML格式。如何发送带有 XML 数据的 REST 请求?

谢谢!

最佳答案

我使用了“fopen”并且它有效。

//You can use 'POST','GET','PUT' or 'DELETE'
$opts = array(
    'http'=>array(
        'method'=>'POST',
        'header'=>"Content-Type: text/xml\r\n" .
            $auth."\r\n",
        'content'=>$xml
    )
);

$context = stream_context_create($opts);

/* Sends an http request to www.example.com
with additional headers shown above */
$fp = fopen($url, 'r', false, $context);
fpassthru($fp);
fclose($fp);

关于PHP:如何使用 XML 数据发送 REST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160838/

相关文章:

rest - HTTP API : Communicating the need to authenticate to a third party

PHP 右移结果为负?

php - 如何将行 ID 从数据库传递到模式对话框?

xml2js : how is the output?

android - ListAdapter setAdapter 返回 null

web-services - 基于文档或 RPC 的 Web 服务

java - 读取属性文件的 RestFul Web 服务

php - 保存搜索结果的数据库结构

php - 用 PHP 制作 Twitter 机器人?

java - 我想以编程方式向我的 android 按钮添加多个字符串(不是通过 XML)