我正在开发Android应用程序和测试目的我测试本地主机它运行完美,但当我托管该服务器的Web服务时,没有响应从该网址返回。Web服务响应不是从我的服务器返回
=>我试过其他网址一样..
https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=your-app-key&pin=110001
,并得到适当的反应如下给出。
{"ResponseCode":2,"ResponseMessage":"Invalid App Key","ResponseDateTime":"1/6/2015 4:50:28 AM GMT","Data":[]}
但从我的服务器url没有任何返回和应用程序显示继续加载数据。 这里是我的doInBackgound()方法
protected String doInBackground(String... strings) {
try {
try{
// url where the data will be posted
//String postReceiverUrl = "http://yoursmarthost.net/~html/androidtest/android_test.php";
String postReceiverUrl="https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY";
// String postReceiverUrl="https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=your-app-key&pin=110001";
//String postReceiverUrl="http://'my url'/android_test.php";
Log.v(TAG, "postURL: " + postReceiverUrl);
// HttpClient
HttpClient httpClient = new DefaultHttpClient();
// post header
HttpPost httpPost = new HttpPost(postReceiverUrl);
// add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("firstname", "Mike"));
nameValuePairs.add(new BasicNameValuePair("lastname", "Dalisay"));
nameValuePairs.add(new BasicNameValuePair("email", "[email protected]"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// execute HTTP post request
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity!=null) {
String responseStr = EntityUtils.toString(resEntity).trim();
Log.v(TAG, "Response: " + responseStr);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
当我更改网址,并把我的网络服务器实际网址,当时
if (resEntity!=null) {
String responseStr = EntityUtils.toString(resEntity).trim();
Log.v(TAG, "Response: " + responseStr);
}
这里
调试指针EntityUtils.toString进入(resEntity).trim()方法但不返回并继续加载显示在Android应用程序屏幕上。