择忆霖心
2017-03-26 01:19
采纳率: 96.7%
浏览 8.1k

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条回答 默认 最新

  • oyljerry 2017-03-26 05:57
    已采纳

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

    已采纳该答案
    打赏 评论
  • 择忆霖心 2017-03-26 02:16
       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();
    
    打赏 评论

相关推荐 更多相似问题