I cannot curl localhost from php, but any other external host works fine.
From cmd I've tried "curl localhost" - it didn't work too, but ingnoring proxy for localhost "curl -v --noproxy localhost" - works.
What is equivalent for this in php?
答案 0 :(得分:2)
You can try setting the proxy to an empty string:
curl_setopt($ch, CURLOPT_PROXY, '');
Another possibility is to add a proxy exception to your env var "no_proxy", but i'm not 100% sure if it affects PHP:
set no_proxy=127.0.0.1
答案 1 :(得分:0)
我也面临着同样的问题。我在一家位于代理服务器后面的公司工作,因此在进行出站呼叫时,我们需要添加代理服务器来卷曲呼叫。但是,对于本地托管的站点,curl调用失败。
对我有用的是这个(CURLOPT_NOPROXY does not affect in PHP是提供链接的问题的更新部分):
curl_setopt($curl, CURLOPT_NOPROXY, 'your-sitename-on-localhost');
当它与URL中的站点名称匹配时,将跳过代理。
以前我收到503,现在它返回本地主机上该站点的正确200状态代码。