亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to solve the error when PHP requests http post page?
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-16 13:16:17
0
5
626

Code:

<?php
/**
 * PHP發(fā)送Json對象數(shù)據(jù)
 *
 * @param $url 請求url
 * @param $jsonStr 發(fā)送的json字符串
 * @return array
 */
function http_post_json($url, $jsonStr){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($jsonStr)
        )
    );
    $response = curl_exec($ch);//執(zhí)行一個cURL會話,成功時返回tru,失敗返回false
    $err = curl_error($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);//獲取最后一次傳輸?shù)南嚓P信息,最后一個收到的HTTP代碼

    curl_close($ch);
 
    return array($httpCode, $response, $err);
}

$time = time();

$url = "https://openapi.lechange.cn/openapi/accessToken";

$str = "phone:17691200000,time:{$time},nonce:49735441495760803893403522385895,appSecret:6d5c2c723dbb4ba78fac5a0e9ece81";

$str = md5($str);

$params = array(
            "system"=>array(
                'ver'=>'1.0',
                'sign'=>$str,
                'appid'=>'lcce1fdddaa5de4322',
                'time'=>"$time",
                'nonce'=>'49735441495760803893403522385895'
            ),
            "params"=>array("phone"=>"17691200000"),
            "id"=>"80"
        );

$jsonparams = json_encode($params);
echo $jsonparams;
list($returnCode, $returnContent, $err) = http_post_json($url, $jsonparams);

echo $returnCode;
var_dump($returnContent);
echo $err;
?>

During execution, two errors will be reported.
(1)SSL certificate problem: unable to get local issuer certificate. After adding the following two lines of code to the php.ini file, this error disappears.

curl.cainfo="D:/wamp64/ca-bundle.crt"
openssl.cafile="D:/wamp64/ca-bundle.crt"

(2) After the above error disappears,

appears
502 Bad Gateway
The proxy server received an invalid response from an upstream server.

There is really no other way now. . Even if the parameters or signature are wrong, the other server will return an error code, but this 502 does not even give the opportunity to return the error code. Ask God to help solve it.

PHP中文網(wǎng)
PHP中文網(wǎng)

認證0級講師

reply all(5)
Peter_Zhu

How come wamp server gets 502? 502 is a reverse proxy error.
Is your local apache+php+mysql+windows running in reverse proxy mode or in apache2 handler mode?

為情所困

Obviously the other party’s website is down... When I open it directly in the browser, it also gets 502

給我你的懷抱

The prompt is more obvious. There is a problem with the backend service, so upstream returns a 502.

The other party's backend service returned a result that the proxy did not accept when responding to your request (usually 4XX, 5XX).

There are two situations:

  1. The other party’s backend service originally believed that there should be no 5XX results (or the other party’s backend service is down), so upstream does not support accepting such results. That is to ask the other party to change the service and not return a 5xx error.

  2. If the other party's backend service believes that it supports using 4xx/5xx to represent some results (common in Restful services), then the other party needs to modify the upstream configuration to support such results to be returned as normal results.

PHPzhong

Set : CURLOPT_SSL_VERIFYPEER => false

洪濤

Request page, interface debugging, use postman. A very useful tool. Simulate the request and you can easily get the request example code

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template