Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

PHP请求http post 页面,报错该如何解决?

代码:

<?php
/**
 * PHP发送Json对象数据
 *
 * @param $url 请求url
 * @param $jsonStr 发送的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);//执行一个cURL会话,成功时返回tru,失败返回false
    $err = curl_error($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);//获取最后一次传输的相关信息,最后一个收到的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;
?>

执行过程中,会报两个错。
(1)SSL certificate problem: unable to get local issuer certificate。php.ini文件中加入下边两行代码后,这个错误消失。

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

(2)以上错误消失后,就出现了

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

现在真的是没有办法了。。即使参数,或者是签名错误,那也是对方服务器返回一个错误码,但是这个502是连返回错误码的机会都不给了。求大神帮忙解决。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

wamp服务器怎么会由502?502是反向代理错误。
你本地的apache+php+mysql+windows是反向代理模式运行还是apache2 handler形式?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...