我使用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}