我想用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
请帮忙.
经过一些实验,我已经弄明白了.这是我的解决方案,以防有人达到死胡同.
$request = new Request( 'POST', $uri, ['Content-Type' => 'text/xml; charset=UTF8'], $xml );
这对Guzzle 6来说对我有用:
// configure options $options = [ 'headers' => [ 'Content-Type' => 'text/xml; charset=UTF8', ], 'body' => $xml, ]; $response = $client->request('POST', $url, $options);