首页 > 解决方案 > 为什么我在向 REST API 发出 HTTP 请求时收到“502 状态错误”?

问题描述

我正在尝试从 REST API 获取一些数据,我已经正确指定了参数,甚至我的访问令牌也是有效的,但我没有得到预期的响应,我正在发出以下 HTTP 请求:

//set parameters
$paramRequest = array(
"title" => "Sample Daily meeting",
"agenda" => "Sample Agenda",
"password" => "BgJep@43",
"start" => "2020-07-01 15:00:00",
"end" => "2020-07-01 16:00:00",
"timezone" => "Asia/Shanghai",
"recurrence" => "FREQ=DAILY;INTERVAL=1;COUNT=10",
"enabledAutoRecordMeeting" => false,
"allowAnyUserToBeCoHost" => false,
);

$cURLConnection = curl_init("https://webexapis.com/v1/meetings");
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $paramRequest);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
                                            'Content-Type: application/x-www-form-urlencoded',
                                            'Connection: Keep-Alive',
                                            'Authorization: Bearer ' . $token 
                                            ));
//send HTTP POST request
$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);

// $apiResponse - available data from the API request
$jsonArrayResponse = json_decode($apiResponse);

//display response
print_r($jsonArrayResponse);

我从 API 收到以下响应:

stdClass Object ( [message] => The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. [errors] => Array ( [0] => stdClass Object ( [description] => The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. ) ) [trackingId] => ROUTER_5EFC3CCD-C466-01BB-0100-AC12DED20100 ) 

标签: phprest

解决方案


推荐阅读