我已經使用xampp設置了一個MySql服務器,我正在創建一個連接到數據庫的android應用程序。我可以使用MYSQL Workbench和ODBC連接器從異地進行連接,並巧妙地無誤地推/拉數據。當連接到EMULATED手機時,我得到「org.apache.http.conn.httphostconnectexception連接到http://x.x.x.x:88/mobile.php拒絕」在DDMS。任何想法,爲什麼這種情況正在發生???獲取「org.apache.http.conn.httphostconnectexception連接到http:// xxxx:88/mobile.php拒絕
允許互聯網是沒有開啓......它是現在,只是驗證,清洗和重新啓動,現在我得到「ClientProtocolException」。
public void getData() {
String result = "";
InputStream isr = null;
try {
HttpClient httpclient = new DefaultHttpClient();
///external ip address not local host or trying inside a local network
HttpPost httpost = new HttpPost("http://x.x.x.x:88/mobile.php");
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
} catch (Exception e) {
Log.e("log.tag", "Error in http connection " + e.toString());
resultView.setText("Could not connect to Database");
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
isr, "iso=8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log.tag", "Error converting result " + e.toString());
}
try {
String s = "";
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(i);
s = s + "User :" + json.getString("UserName");
}
resultView.setText(s);
} catch (Exception e) {
Log.e("log.tag", "Error Parsing Data " + e.toString());
}
}
是你確定你的Manifest有INTERNET權限嗎? – 2014-11-05 22:09:22
確保服務器防火牆未被阻止。或者也許是殺毒軟件。 – 2014-11-05 22:19:02
服務器防火牆也沒有路由器被阻塞,可以通過ODBC和MYSQL Workbench打通,Internet權限沒有被添加,現在是。現在我得到「ClientProtocolException」。 – Glenn 2014-11-05 22:25:40