正确地使用(guzzle)6发送(POST)xml [英] Proper way to send (POST) xml with guzzle 6

查看:496
本文介绍了正确地使用(guzzle)6发送(POST)xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用发送大量xml文件的狂饮来进行发布.我没有找到一个例子.

I want to perform a post with guzzle sending an xml file. I did not find an example.

到目前为止,我要做的是:

What I 've done so far is :

$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

No matter what I try I get back error -1 which means that xml is not valid. XML that I send passes online validation though and is valid %100

请帮助.

推荐答案

经过一些实验,我已经弄清楚了.这是我的解决方案,以防有人死胡同.

After some experiments, I have figured it out. Here is my solution in case someone reaches a dead end.

$request = new Request(
    'POST', 
    $uri,
    ['Content-Type' => 'text/xml; charset=UTF8'],
    $xml
);

这篇关于正确地使用(guzzle)6发送(POST)xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆