localhost のページから応答を読み取ろうとしています。
次のコードがあります。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://myIpAddress/mySite/myFile.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("send_xml", "true"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
InputStream is=response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Log.e(tag, "response: "+sb.toString());
} catch (Exception e) {
Log.e(tag, "error: "+e.toString());
}
logcat で次の応答を取得しています。
09-09 20:56:19.151: ERROR/ca(507): response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
09-09 20:56:19.151: ERROR/ca(507): <html><head>
09-09 20:56:19.151: ERROR/ca(507): <title>403 Forbidden</title>
09-09 20:56:19.151: ERROR/ca(507): </head><body>
09-09 20:56:19.151: ERROR/ca(507): <h1>Forbidden</h1>
09-09 20:56:19.151: ERROR/ca(507): <p>You don't have permission to access /mySite/myFile.php
09-09 20:56:19.151: ERROR/ca(507): on this server.</p>
09-09 20:56:19.151: ERROR/ca(507): </body></html>
PHP 5.3.5、Apache 2.2.17、MySQL 5.5.8 を使用しています。
localhost のファイルにアクセスできないのはなぜですか?
解決策は何ですか?
mySite フォルダーに index.html というファイルがあります。
ありがとうございました。
編集: localhost/mySite/myFile.php を使用するとアクセスできますが、localhost/mySite/myFile.php を使用するとアクセスできません。
しかし、エミュレーターを使用していて、localhost/127.0.0.1 がエミュレートされた電話を返すため、localhost を使用できません。
お役に立てれば。