我的源代码:
final Thread t = new Thread() {
public void run() {
Looper.prepare();
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpResponse response;
JSONObject obj = new JSONObject();
try {
HttpPost post = new HttpPost("http://pc.dyndns-office.com/mobile.asp");
obj.put("Model", ReadIn1);
obj.put("Product", ReadIn2);
obj.put("Manufacturer", ReadIn3);
obj.put("RELEASE", ReadIn4);
obj.put("SERIAL", ReadIn5);
obj.put("ID", ReadIn6);
obj.put("ANDROID_ID", ReadIn7);
obj.put("Language", ReadIn8);
obj.put("BOARD", ReadIn9);
obj.put("BOOTLOADER", ReadIn10);
obj.put("BRAND", ReadIn11);
obj.put("CPU_API", ReadIn12);
obj.put("DISPLAY", ReadIn13);
obj.put("FINGERPRINT", ReadIn14);
obj.put("HARDWARE", ReadIn15);
obj.put("UUID", ReadIn16);
StringEntity se = new StringEntity(obj.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
post.setHeader("host", "http://pc.dyndns-office.com/mobile.asp");
response = client.execute(post);
if (response != null) {
InputStream in = response.getEntity().getContent();
}
} catch (Exception e) {
e.printStackTrace();
}
Looper.loop();
}
};
t.start();
}
}
我想将 Json 对象发送到网站。据我所见,我设置了标题,但仍然出现此异常,有人可以帮助我吗?
(我正在使用 Android-Studio)__
编辑:我不再有任何异常,但我仍然没有收到 json 数据包。
当我手动调用网站时,我得到一个日志文件条目。
有谁知道,怎么了?
Edit2:当我调试时,我得到响应“HTTP/1.1 400 错误请求”,我确定这不是权限问题。有任何想法吗?