我正在开发Android应用程序,并且出于测试目的,我在localhost上测试了它的运行状况,但是当我将该Web服务托管到服务器时,该URL没有响应返回。
=>我试过其他网址。
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应用程序屏幕上显示。
最佳答案
https://www.whizapi.com/api/v2/util/ui/in/indian-city-by-postal-code?AppKey=您的应用密钥和密码= 110001
在此url中,您必须实际编写您的应用程序密钥。
您可以通过登录whizapi.com来获取应用程序密钥,然后转到
https://www.whizapi.com/my-account
您可以通过单击网站右上角的Access WhizApi按钮登录whizapi.com。