2011-09-19 91 views
0

我正在用cURL測試簡單的API。從另一個Apache服務器(另一個php文件)調用一個Apache Server(的一個php文件),。可以在本地進行測試。但是,當我用我的網絡PC測試,它顯示以下403錯誤:cURL在Apache顯示..「訪問被禁止!錯誤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']; 

cURL在兩個Apache的。所以爲什麼?我需要做什麼?

+0

'禁止訪問!您無權訪問請求的對象。它是讀取保護的或不可讀的服務器。「不是一個明確的信息?它是你自己的服務器,你正在查詢或第三方? –

回答

0

如果您使用的是WAMP,請確保您的服務器「在線」」。

其次,

你是htaccess阻止它嗎?

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配置。