0
交方法这是我使用的代码:发送数据与机器人
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost("http://192.168.1.1/value/_0/_0");
JSONObject object = new JSONObject();
try {
object.put("Val", "0");
msg = object.toString();
method.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials("admin", "00000000"), "UTF-8", false));
method.setHeader("Content-Type", "application/json");
method.setEntity(new StringEntity(msg, "UTF8"));
client.execute(method);
}
catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
这里我加入用于认证目的和内容类型的请求报头。这在我不知道什么是错误的。