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

Categories

使用postman直接调试接口,就能够执行改接口代码,但在项目中访问接口就无法执行接口内部代码

clipboard.png

cURL Information 7.19.7

function postServer($url, $params) {

    $curl = curl_init(); // 初始化一个 cURL 对象
    curl_setopt($curl, CURLOPT_URL, $url); // 设置你需要抓取的URL
    curl_setopt($curl, CURLOPT_HEADER, false); // 设置header是否一并显示
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
    curl_setopt($curl, CURLOPT_POST, true); // 使用POST方式传递参数
    curl_setopt($curl, CURLOPT_POSTFIELDS, $params); // 传入参数
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    // curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
    $data = curl_exec($curl); // 运行cURL,请求网页

           // dump(curl_error($curl));                                        // 错误调试
    curl_close($curl); // 关闭URL请求
    return $data;
}

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

1 Answer

当请求的url是本地的url时候,而且是在windows下的话,是会出现这种情况,应该是windows下同端口堵塞了。linux测试就不会,只测试了nginx环境下的。关键字curl php nginx windows


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...