|
...
|
...
|
@@ -62,13 +62,20 @@ class RequestUrlLog extends Command |
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/10 11:36
|
|
|
|
*/
|
|
|
|
public function postRequest($url, $postData) {
|
|
|
|
public function postRequest($url, $postData)
|
|
|
|
{
|
|
|
|
if (empty($header)) {
|
|
|
|
$header = array(
|
|
|
|
"Accept: application/json",
|
|
|
|
"Content-Type:application/json;charset=utf-8",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
|
|
...
|
...
|
@@ -76,13 +83,16 @@ class RequestUrlLog extends Command |
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// 记录请求开始时间
|
|
|
|
$startTime = microtime(true);
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
$res = curl_exec($ch);
|
|
|
|
// 记录请求结束时间
|
|
|
|
$endTime = microtime(true);
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
if (curl_errno($ch)) {
|
|
|
|
curl_error($ch);
|
|
|
|
}
|
|
|
|
$requestTime = round(($endTime - $startTime) * 1000, 2); // 转换为毫秒
|
|
|
|
curl_close($ch);
|
|
|
|
return ['response' => $response, 'http_code' => $httpCode, 'request_time_ms' => $requestTime];
|
|
|
|
return ['response' => $res, 'http_code' => $httpCode, 'request_time_ms' => $requestTime];
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|