PHP CURL错误7无法连接到主机 [英] PHP CURL Error 7 failed to connect to host
问题描述
我有一个特殊的问题,我面对与Php CURL。
I have a peculiar problem i am facing with Php CURL .
我试图通过在centos工作站上运行的php脚本调用在同一网络中的Windows机器上运行的Web服务。我使用CURL。问题是,我可以访问的URL与浏览器,它的工作完美。 BUt当我尝试使用PHP脚本它给出一个错误代码7。
I am trying to call a web service running on a windows machine within the same network via a php script running on a centos workstation. I am using CURL. The problem is that i can access the URL with the browser and it works perfectly. BUt when i try to use the php script it gives an error code 7 .
如果我尝试本地ip地址和google在php脚本它工作没有问题。可能是什么问题?我一直在试图让我围绕这个问题在过去几个小时,但我不能排序。
HOwever if i try a local ip address and google in the php script it works with no issues. What could be the issue? I have been trying to get me head around this issue for the past few hours but i am not able to sort it.
我也想添加,当我使用crl通过终端我得到一个正确的答复。 HTTP 200OK
I would also like to add, when i use crl via the terminal i get a proper reply. HTTP 200OK
需要帮助:)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13',
CURLOPT_VERBOSE => 1,
CURLOPT_PORT => 9710,
CURLOPT_URL => 'http://192.168.100.4:9710/http/send-message?message='.$message
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo "<br>Error Code : " .curl_errno($curl);
推荐答案
Centos机器上启用了selinux,造成这个问题。感谢您的帮助。
There was selinux enabled on the Centos Machine, and that was causing the problem. Thanks for your help guys.
这篇关于PHP CURL错误7无法连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!