Http客户端发送 Multipart 表单请求 post请求问题

晚安。

截图

https://www.workerman.net/plugin/94
截图
现在这样报错

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
1158 1 0
1个回答

sbf
//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 );
}

看看源码,多传了个参数 form_params

  • 晚安。 2022-12-13

    $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());
年代过于久远,无法发表回答
×
🔝