【发布时间】:2017-01-07 10:50:31
【问题描述】:
这是我正在使用的代码:
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();
}
在这里,我添加了用于身份验证目的和请求内容类型的标头。我不知道这有什么问题。
【问题讨论】: