我想用 guzzle 发送一个 xml 文件来执行一个帖子。我没有找到例子。
到目前为止我所做的是:
$xml2=simplexml_load_string($xml) or die("Error: Cannot create object");
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new Client();
//
$request = new Request('POST', $uri, [ 'body'=>$xml]);
$response = $client->send($request);
//
//$code = $response->getStatusCode(); // 200
//$reason = $response->getReasonPhrase(); // OK
//
echo $response->getBody();
无论我尝试什么,我都会返回错误 -1,这意味着 xml 无效。 我发送的 XML 虽然通过了在线验证并且有效 %100
请帮忙。
最佳答案
这就是我在 Guzzle 6 上的工作方式:
// configure options
$options = [
'headers' => [
'Content-Type' => 'text/xml; charset=UTF8',
],
'body' => $xml,
];
$response = $client->request('POST', $url, $options);
关于php - 使用 guzzle 6 发送 (POST) xml 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34726530/