为什么对于第一个String,“jsonGetMethod”方法有效,但是使用第二个和第三个字符串 - 不是吗?当我从Android Web浏览器中的所有字符串输入URL时 - 我看到了json响应。 (我正在使用通过Wi-Fi连接到互联网的Eclipse,Real Android Device(非模拟器),在AndroidManifest Internet Permission中添加。)
//This String works fine
private static String url = "http://json-ld.org/contexts/person.jsonld";
//Log.d(jsonStr) shows "null"
private static String url = "http://192.168.1.200:8080/test/json";
//Exception throws
private static String url = "192.168.1.200:8080/test/json";
public String jsonGetMethod(String url)
{
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
String jsonStr = jsonGetMethod(url);
Log.d(jsonStr);