大神,我在用http工具,用到raw,post提交要怎么提交呢?而且要选择是application/json
6 回复
这我样提交,还是会报401的错误,但是在postMan是有效的。
Request req = Request.create("http://127.0.0.1:8080/api/login/service", METHOD.POST);
Header header = Header.create();
header.set("Authorization", "Bearer TcndRr8EMrXvfktJGHxlDjs2dsYDlxdM");
header.set("OriginFrom", "2_T");
header.set("Content-Type", "application/json");
header.set("cache-control","no-cache");
header.set("data", "{ \"phone\":\"18516520078\", \"password\":\"qaz123456\", \"userIp\":\"196.0.0.1\", \"loginTime\":\"2017-12-31 20:08:59\" }");
Response resp = Sender.create(req).send();
if (!resp.isOK()) {
}
再贴一段postMan给到的
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, " { \"phone\":18516520078, \"password\":\"qaz123456\", \"userIp\":\"196.0.0.1\", \"loginTime\":\"2017-12-31 20:08:59\" }");
Request request = new Request.Builder()
.url("http://127.0.0.1:8080/api/login/service")
.post(body)
.addHeader("authorization", "Bearer TcndRr8EMrXvfktJGHxlDjs2dsYDlxdM")
.addHeader("originfrom", "2_T")
.addHeader("content-type", "application/json")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "7d1e9066-fd19-d896-dd90-e8dea37cb231")
.build();
Response response = client.newCall(request).execute();
添加回复
请先登陆