[英]Timeout exception in android studio while trying to get a response from an asp.net web api call
I am trying to consume an asp.net web api in android that takes around 17500 ms to respond(as per postman). 我正在尝试消耗android中的asp.net网络api,它需要大约17500毫秒来响应(根据邮递员)。 It is giving me a timeout error in android studio.
它给我在android studio中的超时错误。 But when I try to explicitly run the api using postman I am getting the desired result.
但是,当我尝试使用邮递员显式运行api时,得到了预期的结果。
Here is the snippet: 这是代码段:
java.net.URL url = new java.net.URL(vehicleurl);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
conn.setConnectTimeout(15000000);
Request req = new Request.Builder()
.url(vehicleurl)
.build();
Response response = client.newCall(req).execute();
Try this . 尝试这个 。
in your manifest
. 在你的
manifest
。
<uses-permission android:name="android.permission.INTERNET"/>
Edit 编辑
HttpURLConnection HttpURLConnection
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
// edit here ,change time
connection.setConnectTimeout(20000);
connection.setReadTimeout(20000);
OKHttp OKHttp
private final OkHttpClient client;
public ConfigureTimeouts() throws Exception {
client = new OkHttpClient.Builder()
.connectTimeout(100, TimeUnit.SECONDS)
.writeTimeout(100, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.