android okhttp3
一、
传键值对
public String webLogin() { String responseData = null; OkHttpClient client = new OkHttpClient(); TextView tvUser = findViewById(R.id.EditTextUser); TextView tvPassWord = findViewById(R.id.EditTextPassWord); String user = tvUser.getText().toString(); String passWord = tvPassWord.getText().toString(); RequestBody body = new FormBody.Builder().add("User", user).add("PassWord", passWord).build(); //请求 Request request = new Request.Builder().addHeader("Content-Type","application/json;charset=utf-8").url("网址").post(body).build(); try { Response response = client.newCall(request).execute(); responseData = response.body().string(); } catch (IOException e) { e.printStackTrace(); } return responseData; }
二、
传字符串