这里要注意如果想发送同步请求,而不报错需要在oncreate方法中加上
if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
1.这里用个例子看如何来在android中使用HttpURLConnection 同步post请求到springboot后台
2.这里我用了一个工具类实现的登录
String mddLoginResult = "";
mddLoginResult = YdHttpPostUtils.mddLogin(username,password);
3.看看这个login方法是怎么写的
public static String mddLogin(String username,String password) {
// 请求url
String url = "http://172.19.188.199:8080/api/test/user/login";
try {
Map<String, Object> map = new HashMap<>();
map.put("username", username);
map.put("password", password);
String param = GsonUtils.toJson(map);
String result = HttpUtil.post(url, "a