Sorry, I really don't know how to write the title of my question
I am doing a PHP process using third parties API demo, in my computer (XAMPP) working well, but when I upload to my website, will be 502 error.
I have 2 files, class.php
(API demo from third parties) and my.php
In class.php
class QF_HTTP_CLIENT{
public $domain = ''; // 站点hostname
public $token = ''; // 开放平台token
/**
* @param string $method 请求方式
* @param string $path 请求路径
* @param array $requestBody 请求体参数
* @return array
* @throws Exception
*/
private function _request($method, $path, $requestBody)
{
$header = array(
"Authorization: Bearer {$this->token}",
"Content-Type: application/x-www-form-urlencoded",
"Cache-Control: no-cache",
"Accept: application/json",
"User-Agent: QianFanHttpClient/1.0.0"
);
$url = "{$this->domain}/openapi/{$path}";
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
//much code here...
$data = json_decode($response, true);
if (json_last_error() != JSON_ERROR_NONE) {
$error = json_last_error_msg();
$errno = json_last_error();
throw new Exception("Json Parsing Error #{$errno}. $error", 1);
}
return $data;
}
public function post($path, $data)
{
return $this->_request('POST', $path, $data);
}
}
$abc = 'gg.com';
$efg = 'abc1234'
$client = new QF_HTTP_CLIENT();
$client -> domain = $abc;
$client -> token = $efg;
In my.php
,
<?php
if(file_exists('class.php')){
$qfappon = 1;
required 'class.php';
}
if($qfappon == '1'){
$rrr = $client->post(some of script here);
}
//my other script...
?>
My localhost, I delete class.php
, doesn't fulfill the condition, so PHP
ignore the $rrr = $clien......
, and my localhost webpage running well.
But when I upload this my.php
to my server without class.php
also, my server webpage show 502 error. If I delete the $rrr = $client->post(some of script here);
in my.php
then my webpage will run as normal.
I feel like, at my server, even $qfappon
is a blank value, doesn't match the condition, my server still process the script $rrr = $client->post(some of script here);
, since $client->post
class (missing) doesn't exist, so my webpage become 502 error.
Is it php version cause this? my server PHP 5.3.29, my XAMPP localhost 7.4.13