-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostTest.java
More file actions
39 lines (37 loc) · 1.41 KB
/
PostTest.java
File metadata and controls
39 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package okhttp3;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.Map;
import model.User;
/*
* author yongkai.sun
*/
public class PostTest {
public static void main(String[] args) throws JsonProcessingException {
OkHttpClient okHttpClient = new OkHttpClient();
User user = new User();
user.setCode("Ser_yanlei.zhu");
Map map = Maps.newHashMap();
map.put("code","Ser_yanlei.zhu");
ObjectMapper objectMapper = new ObjectMapper();
String s = objectMapper.writeValueAsString(map);
RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), s);
Request request = new Request.Builder().url("http://localhost:8084/online/pac/user/login")
.post(requestBody).build();
try {
Response response = okHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
String string = response.body().string();
if ("true".equals(string)) {
// return "redirect:http://localhost:8084";
System.out.println("2");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}