我在ubuntu上安装了一个django服务器,我想从中获取json数据并在android设备上显示,但我不知道服务器名。
我尝试了10.0.2.2、localhost、127.0.0.1和ip地址,但都没有成功。像:
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new DefaultHttpClient();
HttpGet method = new HttpGet("http://localhost:8000/books/4/?format=json");
try {
HttpResponse response = httpClient.execute(method);
InputStream is = response.getEntity().getContent();
content[0] = IStoString(is);
Log.i("SERVERTEST", content[0]);
} catch (ClientProtocolException r) {
r.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
thread.start();
该代码与其他api一起工作。
例外情况是:连接到
http://127.0.0.1:8000
拒绝