[英]okhttp3 fail to request for android project
I am using okhttp
, for my Android project. 我在我的Android项目中使用
okhttp
。 All the requirements work good but when I need to call a request for a client it will show the error below: 所有要求都可以正常工作,但是当我需要为客户 调用请求时 ,它将显示以下错误:
> The method newCall(Request) is undefined for the type OkHttpClient
I need to create a call like this: 我需要创建一个像这样的电话:
Call call = client.newCall(request);
Please check which version of OkHttpClient
are you already using. 请检查您已经在使用哪个版本的
OkHttpClient
。 As Jake Wharton states: newApi()
is reserved only for newest 2.x
version. 正如杰克·沃顿所言:
newApi()
仅保留用于最新的2.x
版本。 Please take a look at: https://github.com/square/okhttp/issues/814 请看一下: https : //github.com/square/okhttp/issues/814
Please upgrade your OkHttpClient
to latest version. 请升级您的
OkHttpClient
到最新版本。 Put into Gradle file 放入Gradle文件
compile 'com.squareup.okhttp3:okhttp:3.0.1'
Then, in your activity import: 然后,在您的活动中导入:
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
Hope it help 希望对你有帮助
Make sure that you have correct import classes listed, and that you are not mixing old classes with new ones. 确保列出了正确的导入类,并且没有将旧类与新类混在一起。
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.