[英]localhost xampp curl port 80 error
在從本地xampp進行cUrl
,單個URL端點似乎出現問題。
我收到一條錯誤消息: Failed to connect to localhost port 1080: Connection refused
即使設置了curl_setopt($ch, CURLOPT_PORT, 80);
Failed to connect to localhost port 1080: Connection refused
curl_setopt($ch, CURLOPT_PORT, 80);
。
但這僅發生在特定的URL(沒有ssl http://)中 ,其他帶有https://的URL也可以。 所有其他到不同端點的參數都可以。
在實時服務器上,有問題的端點,相同的代碼一切正常。
誰能幫助我了解為什么會這樣嗎?
我的http.conf: ServerName localhost:80
完整的代碼
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
// "Cache-Control: max-age=0",
// "Connection: keep-alive",
// "Keep-Alive: 300",
"Content-Type: application/json",
'Api-Key: ' . $apiKey,
));
$output = curl_exec($ch);
//curl_easy_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$errmsg = curl_error ( $ch );
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
$httpHeaders = curl_getinfo($ch);
curl_close($ch);
print_r($ch);
echo $httpcode;
print_r($httpHeaders);
print_r($errmsg); // Failed to connect to localhost port 1080: Connection refused
一整天后, 解決方法是為代理設置一個空值並使用端口80
curl_setopt($ch, CURLOPT_PROXY, ''); //!! FIX
curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);
我有同樣的問題,我通過在其他端口上運行apache解決了它,您應該編輯httpd.conf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.