我創建了一個應用程序,它使用php從mysql獲取數據。但是,當我從我的Android應用程序調用PHP文件時,我將下面的內容放到了我的LogCat窗口中。使用PHP到Android無法從MySql獲取數據?
08-26 21:07:57.748: V/(1036): Response : [email protected]
08-26 21:07:57.758: V/(1036): Entity : [email protected]
08-26 21:07:57.839: V/(1036): Result : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
08-26 21:07:57.839: V/(1036): <html><head>
08-26 21:07:57.839: V/(1036): <title>403 Forbidden</title>
08-26 21:07:57.839: V/(1036): </head><body>
08-26 21:07:57.839: V/(1036): <h1>Forbidden</h1>
08-26 21:07:57.839: V/(1036): <p>You don't have permission to access /PHP/getAllPeopleBornAfter.php
08-26 21:07:57.839: V/(1036): on this server.</p>
08-26 21:07:57.839: V/(1036): </body></html>
但是,當我使用wamp服務器運行.php時,它可以成功獲取數據。我無法理解我犯了什麼錯誤。
以下是我的Android代碼
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.167.122.24 /PHP/ getAllPeopleBornAfter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Log.v("","Response : "+response);
Log.v("","Entity : "+entity);
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
Log.v("","Result : "+result);
}catch(Exception e){
Log.v("log_tag", "Error in http connection "+e);
}
請給我一些想法。先謝謝你。
沒有你的服務器有htaccess的認證? –
謝謝你的建議,但你能告訴我在哪裏可以找到htaccess認證。我在本地機器上使用了wamp服務器。等待你的重播......... – himAndroid
當你在瀏覽器中打開這個URL時,它會詢問你的服務器是否有htaccess認證。 –