Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对于post 请求 Query Params方式传参?怎么传? #10

Open
honganxue opened this issue Sep 29, 2020 · 5 comments
Open

对于post 请求 Query Params方式传参?怎么传? #10

honganxue opened this issue Sep 29, 2020 · 5 comments

Comments

@honganxue
Copy link

No description provided.

@kongzue
Copy link
Owner

kongzue commented Sep 29, 2020

您好,请使用 HttpUrl 创建,在传入 url 参数时使用 httpUrl.toString():

HttpUrl httpUrl= new HttpUrl.Builder()
    .scheme("https")
    .host("www.example.com")
    .addQueryParameter("key", "value")
    .build();

请求时:

HttpRequest.build(context, httpUrl.toString())
        .setResponseListener(new ResponseListener() {
            @Override
            public void onResponse(String response, Exception error) {
                ...
            }
        })
        .doPost();

@honganxue
Copy link
Author

host 传入ip地址报错

@kongzue
Copy link
Owner

kongzue commented Sep 29, 2020

请说明是什么错误

@honganxue
Copy link
Author

image
2020-09-29 12:47:16.125 11246-11246/com.example.transferstation.activity E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.transferstation.activity, PID: 11246
java.lang.IllegalArgumentException: unexpected host: 120.24.62.145:8153/admin/login/token
at okhttp3.HttpUrl$Builder.host(HttpUrl.java:1035)
at com.example.transferstation.activity.LoginActivity.login(LoginActivity.java:89)
at com.example.transferstation.activity.LoginActivity$2.onClick(LoginActivity.java:77)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@kongzue
Copy link
Owner

kongzue commented Sep 29, 2020

您好,您的创建方式有误。
请使用如下方式创建:

HttpUrl httpUrl = new HttpUrl.Builder()
        .scheme("http")
        .host("120.24.62.145")
        .port(8153)
        .addPathSegment("admin")
        .addPathSegment("login")
        .addPathSegment("token")
        .addQueryParameter("password","123456")
        .addQueryParameter("username","test")
        .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants