Merge pull request #249 from zhamao-robot/fix-zmrequest-array-bug

优化 ZMRequest POST 数据时允许直接传入数组
This commit is contained in:
Jerry 2023-01-08 17:02:35 +08:00 committed by GitHub
commit 06964a97f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,6 +57,10 @@ class ZMRequest
'url' => ($url instanceof UriInterface ? $url->__toString() : $url),
], $config));
$socket->withoutAsync();
if (is_array($data)) {
$data = http_build_query($data);
$header['Content-Type'] = 'application/x-www-form-urlencoded';
}
$obj = $socket->post($data, $header, fn (ResponseInterface $response) => $response, fn () => false);
if ($obj instanceof ResponseInterface) {
if ($obj->getStatusCode() !== 200 && $only_body) {