简体   繁体   English

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

[英]cURL on Apache showing .. “Access forbidden! Error 403”

I am testing simple API with cURL. 我正在使用cURL测试简单的API。 It is, calling from (a php file of) one Apache Server to (a php file of) another Apache Server . 即, 从一个Apache服务器(的一个php文件)调用另一个Apache服务器的(一个php文件) It is ok testing locally. 可以在本地测试。 But when i test with my network PCs, it showing following 403 error: 但是当我用网络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

Codes for Caller Server (Server 1) are: 呼叫方服务器(服务器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);


Codes for Answering Server (Server 2) are: 应答服务器(服务器2)的代码为:

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

cURL is enabled on both Apache. 在两个Apache上都启用了cURL。 So why? 所以为什么? What do i need to do? 我需要做什么?

This is nothing to do with cURL, it is your Apache configuration that is the problem. 这与cURL无关,这是您的Apache配置引起的问题。

Apache is configured in such a way the the resource at api.php is not available to the machine on which your script is running. Apache的配置方式使api.php的资源不可用于运行脚本的计算机。

In you Apache configuration, for the root directory, you need to inspect these directives: 在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

Have a look at this and the sections immediately below it. 看看和它下面的部分。

Alternatively, you may have some code somewhere in api.php that looks something like 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");

...however, based on what you say is in your code, I think this is about the Apache configuration. ...但是,根据您在代码中所说的内容,我认为这与Apache配置有关。

If you are using WAMP, make sure you "put online" the server. 如果您使用的是WAMP,请确保将服务器“联机”

Secondly, 其次,

Is you htaccess blocking it ? 您是htaccess阻止它吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM