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

 二、

传字符串

 

posted @ 2018-12-14 16:35  富坚老贼  阅读(228)  评论(0编辑  收藏  举报