我正在尝试在android中使用一个asp.net web api,需要大约17500毫秒才能响应(按照邮差)。它在android studio中给我一个超时错误。 但是当我尝试使用邮递员明确地运行api时,我得到了理想的结果。
以下是摘录:
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();
答案 0 :(得分:0)
试试这个。
在manifest
。
<uses-permission android:name="android.permission.INTERNET"/>
修改强>
HttpURLConnection类
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
// edit here ,change time
connection.setConnectTimeout(20000);
connection.setReadTimeout(20000);
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();
}