我正在做一个OCR项目,我正在使用vidado API进行尝试。当我通过posman发送一个post请求时,它会给出正确的响应,但是当我从php调用API时,它会给出以下错误
Client error: `POST https://api.vidado.ai/read/text` resulted in a `400 Bad Request` response: {"detail":"There was an error parsing the body"}我的代码是
$client = new \GuzzleHttp\Client();
$url = "https://api.vidado.ai/read/text";
$requestAPI = $client->post( $url, [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'my apikey',
'Content-Type' => 'multipart/form-data'
],
'form_params' => [
'autoscale' => 'true',
'image'=> $img
],
]);在邮递员中,我的要求如下


有人注意到了实际的错误吗?所以请给我一个方法来做这个。谢谢。
发布于 2020-08-03 03:51:48
与口香糖文件合奏
备注 多部件不能与form_params选项一起使用。你需要使用一个或另一个。应用程序/x-www-表单-urlencoded请求使用form_params,多部分/表单-数据请求使用多部分。 此选项不能与body、form_params或json一起使用。
因此,不能在多部分/表单数据中使用form_params,而必须以这种方式使用多部分方法:
$client = new \GuzzleHttp\Client();
$url = "https://api.vidado.ai/read/text";
$requestAPI = $client->request('POST', $url, [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'my apikey',
'Content-Type' => 'multipart/form-data'
],
'multipart' => [
[
'name' => 'image',
'contents' => fopen('/path/to/file', 'r'),
'filename' => 'custom_filename.jpg'
],
[
'name' => 'autoscale',
'contents'=> true
]
]
]);https://stackoverflow.com/questions/63222523
复制相似问题