2011-09-19 17 views
0

私はcURLで簡単なAPIをテストしています。それは、(のPHPファイル)から別のApacheサーバー(のPHPファイル)への呼び出しです。です。ローカルでのテストはOKです。私は自分のネットワークPCでテストする場合でも、それは403エラー以下を示す:発信者サーバ(サーバ1)のためのApache上のcURL .. "Access forbidden!Error 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

コードは以下のとおりです。サーバー(サーバーに答えるため

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を使用している場合は、「オンラインにする」サーバーを確認してください。

第2に、

あなたは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の設定についてだと思います。