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;
}

二、

传字符串

上一篇:Windows服务器【由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作】问题调查


下一篇:nginx转发tomcat请求转成https后页面不能下载apk文件而是直接打开