OkHttp - 404 Not Found

时间:2017-12-19 11:50:08

标签: android okhttp

我使用OkHttpClient来获取API密钥,但获得响应

{protocol=h2, code=404, message=, url=https://unknown.com/api.php} 

以下代码,我正在使用。

OkHttpClient client1 = new OkHttpClient();
HttpUrl.Builder urlBuilder = 
HttpUrl.parse("https://unknown.com/api").newBuilder();
                urlBuilder.addQueryParameter("os_version", "Android 25");
                urlBuilder.addQueryParameter("user_id", "12345");
                urlBuilder.addQueryParameter("device", "Android");

                String url = urlBuilder.build().toString();

                Request request = new Request.Builder()
                        .url(url)
                        .build();
                try{
                    Response response = client1.newCall(request).execute();
                    Log.e("response",""+ response.body().string());

                }catch (Exception e){
                   Log.e("MSG",""+e.getMessage());
                }

以前,我使用的是namevalue对,但它只适用于6.0及以上而不适用于5.0,因此我切换到OkHttp但无法获得正确的响应。 我正在关注

 compile 'com.squareup.okhttp:okhttp:2.5.0'

日志:

Response{protocol=h2, code=404, message=, url=https://unknown.com/api.php}

0 个答案:

没有答案