http://www.wtbis.cn/plugin/94
現(xiàn)在這樣報(bào)錯(cuò)
GuzzleHttp\Exception\InvalidArgumentException: You cannot use form_params and multipart at the same time. Use the form_params option if you want to send application/x-www-form-urlencoded requests, and the multipart option to send multipart/form-data requests
//https://github.com/yzh52521/easyhttp/blob/master/src/Request.php
/**
* Request constructor.
*/
public function __construct()
{
$this->client = $this->getInstance();
$this->bodyFormat = 'form_params'; // 注意這里的初始化
$this->options = [
'http_errors' => false,
];
if (!$this->handlerStack instanceof HandlerStack) {
$this->handlerStack = HandlerStack::create( new CurlHandler() );
}
$this->options['handler'] = $this->handlerStack;
}
public function post(string $url,array $data = [])
{
$this->options[$this->bodyFormat] = $data; // 這里
return $this->request( 'POST',$url,$data );
}
看看源碼,多傳了個(gè)參數(shù) form_params
$response = Http::attach('filename', file_get_contents('1.txt'), '1.txt', [
'enctype' => 'multipart/form-data'
])
->withBasicAuth($a, $b)
->post('https://api.aa.cn/v3');
print_r($response->array());