Skip to content

Commit

Permalink
Merge pull request #136 from wonder-game/develop
Browse files Browse the repository at this point in the history
feat: 增加addData和setData功能
  • Loading branch information
linkunyuan authored Dec 18, 2024
2 parents 210216e + 4251d11 commit a632241
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Common/Classes/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ protected function _hCurl($url, $data, $method, $header, $option)
call_user_func_array([$client, $k], $v);
}

if (!empty($option['addData'])) {
$cli = $client->getClient();
foreach ($option['addData'] as $key => $value) {
if ($value instanceof \CURLFile) {
continue;
}
if (is_array($value)) {
foreach ($value as $v) {
if ($v instanceof \CURLFile) {
continue 2;
}
}
}
$cli->addData($key, $value);
}
}

if ( ! empty($option['setData'])) {
$cli = $client->getClient();
$cli->setData($option['setData']);
}

$calls = [
'get' => function ($data) use ($client) {
$client->setQuery($data);
Expand Down Expand Up @@ -163,7 +185,7 @@ protected function _curl($url, $data, $method, $header, $option)
case 'patch':
case 'options':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case 'head':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
Expand Down

0 comments on commit a632241

Please sign in to comment.