简体   繁体   English

尝试从asp.net Web API调用获取响应时,Android Studio中出现超时异常

[英]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.

相关问题 试图从 ASP.NET Web API 获取文件响应 - Trying to get file response from ASP.NET Web API Asp.net 核心 Web API 使用 Dapper 执行 Postgres function 引发“读取超时”和“读取流时异常” - Asp.net Core Web API use Dapper to Execute Postgres function raise "Timeout during reading" and "Exception while reading from stream" 无法从ASP.NET Web API获得响应 - Can't get response from ASP.NET web API 有没有办法在保持实例运行的同时将API调用的响应返回给ASP.NET? - Is there a way to return a response from an API call to ASP.NET while keeping the instance running? 无法从 ASP.NET Web API 获得任何响应 - Can't get any response from ASP.NET Web API 从AngularJS调用ASP.NET Web API会引发异常 - Calling ASP.NET Web API from AngularJS throws exception 服务器花费太多时间发送响应-ASP.NET Web API中的超时错误 - Server takes too much time to send a response - timeout error in ASP.NET Web API 试图从asp.net Web API帖子中获取正确的JSON格式 - Trying to get right JSON format from a asp.net Web API post 如何在asp.net中调用Java Servelet并从中获得响应? - How to Call Java Servelet and get response from it in asp.net? ASP.NET Web API抛出异常 - ASP.NET Web API Throw Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM