GuzzleHttp使用

载入

1
2
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

获取远程xml

1
2
3
4
5
6
7
8
9
10
11
12
$client = new Client();

#基础配置
$options = [
'headers' => [
'Content-Type' => 'text/xml; charset=UTF8',
],
'body' => $xml,
];

$response = $client->request('POST',$URL,$options);
$responseXML = $response->getBody()->getContents();

获取远程文件

1
2
3

$client = new Client(['verify' => false]);
$data = $client->request('get',$resURL)->getBody()->getContents();