okhttp3中的post请求问题

大神看一下,我这个POST请求那里错了,直接说出来。谢谢大神

    String username = usernameEdit.getText().toString();
                String password = passwordEdit.getText().toString();
                OkHttpClient client = new OkHttpClient();
                RequestBody requestBody = new FormBody.Builder()
                        .add("username", username)
                        .add("password", password)
                        .build();
                Request request = new Request.Builder()
                        .url("http://test.ourwechat.com/test/auth.php")
                        .post(requestBody)
                        .build();
                try {

                    Response response =client.newCall(request).execute();
                    response.body().string();
                } catch (IOException e) {
                    e.printStackTrace();
                }

2个回答

调用方法没问题,你打印的错误信息是什么

qq_37961932
择忆霖心 错误信息有一个指向的是Response response =client.newCall(request).execute();
3 年多之前 回复
qq_37961932
择忆霖心 方便加qq吗
3 年多之前 回复
   String username = usernameEdit.getText().toString();
                String password = passwordEdit.getText().toString();
                OkHttpClient client = new OkHttpClient();
                RequestBody requestBody = new FormBody.Builder()
                        .add("username", username)
                        .add("password", password)
                        .build();
                Request request = new Request.Builder()
                        .url("http://test.ourwechat.com/test/auth.php")
                        .post(requestBody)
                        .build();
                try {

                    Response response =client.newCall(request).execute();
                    response.body().string();
                } catch (IOException e) {
                    e.printStackTrace();
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐