Apache上的cURL显示..“禁止访问!错误403”

时间:2011-09-19 10:56:55

标签: php apache curl

我正在使用cURL测试简单的API。它是,从一个Apache服务器的(一个php文件)调用到另一个Apache服务器的(一个php文件)。可以在本地进行测试。但是,当我使用我的网络PC进行测试时,它显示以下403错误:

Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403

来电服务器(服务器1)的代码是:

function apicall($request_url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $request_url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $return = curl_exec($ch);
    curl_close($ch);
    return $return;
}
$request_url = 'http://192.168.1.205/api.php?cname=David';
$response = apicall($request_url);


应答服务器(服务器2)的代码是:

echo "Hello ".$_GET['cname'];

两个Apache都启用了cURL。所以为什么?我需要做什么?

2 个答案:

答案 0 :(得分:1)

这与cURL无关,这是你的Apache配置问题。

Apache的配置方式是api.php上的资源不适用于运行脚本的计算机。

在Apache配置中,对于根目录,您需要检查这些指令:

# Yours will not look like this
# The key point is look at the 'Order' and 'Allow'/'Deny' directives for the root directory
Order allow,deny
Allow from all

查看this及其下方的部分。

或者,您可能在api.php中的某处看起来像这样的代码:

header('HTTP/1.1 403 Forbidden');
exit("Access forbidden!\nYou don't have permission to access the requested object. It is either read-protected or not readable by the server.\nIf you think this is a server error, please contact the webmaster.\nError 403");

...但是,根据您在代码中所说的内容,我认为这是关于Apache配置的。

答案 1 :(得分:0)

如果您使用的是WAMP,请确保“联机”服务器。

其次,

你是否阻止它?