我需要在 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/