我正在尝试通过传递 lat 和 lon 以及 userID 来使用 sampleURL 调用 REST Web 服务。但我总是null
输入字符串数据。有什么建议为什么会发生?我正在使用安卓系统。但是当我尝试在浏览器中打开该 url 时,它会被打开并且我可以看到响应。我猜我的代码有问题。
private class GPSLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
String data = findUsersInCurrentRadius(1,location.getLatitude(),location.getLongitude());
System.out.println("Got Data" +data);
textView.setText(data);
}
private String findUsersInCurrentRadius(int userid, double lat, double lon) {
String sampleURL = SERVICE_URL + "/"+REMOTE_METHOD_NAME+"/"+userid+"/"+lat+"/"+lon;
System.out.println(sampleURL);
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(sampleURL);
String text = null;
try {
HttpResponse response = httpClient.execute(httpGet, localContext);
System.out.println("Some Response" +response);
HttpEntity entity = response.getEntity();
text = getASCIIContentFromEntity(entity);
} catch (Exception e1) {
return e1.getLocalizedMessage();
}
return text;
}
}