Workerman\Http\Client multipart/form-data问题

$multipart = [
[
'name' => 'video_url',
'contents' => 'https://xxx/123.mp4'
],
[
'name'=>'advertiser_id',
'contents'=>xxx,
]
];
$token = 'xxxxx';
$boundary = $multipart->getBoundary();
$url = 'https://api.oceanengine.com/open_api/2/file/video/ad/';
$http->request($url, [
'method' => 'POST',
'version' => '1.1',
'headers' => [
'Connection' => 'keep-alive',
'Content-Type' => "multipart/form-data",
'Access-Token' => $token ,
],
'data' => $multipart,
'success' => function ($response)use($itemId,$videoId,$accountId) {
Log::channel('ocean')->info('检查同主体-日志id:'.$itemId.'-视频id:'.$videoId.'-户id:'.$accountId.'-结果:'.$response->getBody());
echo '正常结束:'.$response->getBody().'|id:'.$itemId.PHP_EOL;
},
'error' => function ($exception)use($itemId,$videoId,$accountId) {
Log::channel('ocean')->info('检查同主体-日志id:'.$itemId.'-视频id:'.$videoId.'-户id:'.$accountId.'-结果:异常退出'.$exception);
echo '异常退出:'.$exception.'|'.$itemId.PHP_EOL;
}]
);
请求巨量的api时,会一直等待异常超时退出,用GuzzleHttp\Client 就正常请求。是我请求体有问题吗

355 1 0
1个回答

sm2010

按照文档 'Content-Type' 应该是 "multipart/form-data; boundary=$boundary",你写成了 "multipart/form-data"
还有巨量请求时对方接口负载高了返回慢超时也正常吧,不一定是你代码问题。GuzzleHttp\Client 阻塞调用并发和workerman http-client异步并发不是一个数量级的,GuzzleHttp\Client并发提不起来所以可能表现正常。

×
🔝