开发者

cURL on Apache showing .. "Access forbidden! Error 403"

开发者 https://www.devze.com 2023-04-06 08:17 出处:网络
I am testing simple API with cURL. It is, calling from (a php file of) one Apache Server to (a php file of) another Apache Server. It is ok testing locally. But when i test with my network PCs, it sho

I am testing simple API with cURL. It is, calling from (a php file of) one Apache Server to (a php file of) another Apache Server. It is ok testing locally. But when i test with my network PCs, it showing following 403 error:

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:

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:

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

cURL is enabled on both Apache. So w开发者_如何学JAVAhy? What do i need to do?


This is nothing to do with cURL, it is your Apache configuration that is the problem.

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.

In you Apache configuration, for the root directory, you need to inspect these directives:

# 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:

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.


If you are using WAMP, make sure you "put online" the server.

Secondly,

Is you htaccess blocking it ?

0

精彩评论

暂无评论...
验证码 换一张
取 消