HttpClient hangs when timeout is setting (Windows Phone)

HttpClient hangs when timeout is setting (Windows Phone)

Content Index :

HttpClient hangs when timeout is setting (Windows Phone)
Tag : chash , By : aspitzer
Date : December 01 2020, 04:55 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

HttpClient - setting a "global" socket timeout, and a separate timeout per request

Tag : java , By : Keonne Rodriguez
Date : March 29 2020, 07:55 AM
Hope this helps With HttpClient, I am setting the default socket/connection timeout with the following: , If you are using HttpClient 4.0 you could do this :
mClient = new DefaultHttpClient(connectionManager, params) {
  protected HttpParams determineParams(HttpRequest req) {
    //Fill in your impl here

HttpClient request succeeds with timeout defined, but hangs without

Tag : java , By : Wilfred Knigge
Date : March 29 2020, 07:55 AM
may help you . I found the answer! Turns out HttpClient only allows a certain number of connections at a time. According to my code, the default maximum connections is 2. I needed to close each connection after they were complete and the upload ran fine.
Fixed code adds request connection release.
private void uploadParts(String assetId) throws IOException {
    //set up post request
    HttpClient client = HttpClientBuilder.create().build();

    String url = "";

    //prepare video
    File video = new File("files/video.mp4");
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(video));

    int partMaxSize = 1024 * 1024 * 5;
    byte[] buffer = new byte[partMaxSize];
    double fileSize = video.length();
    System.out.println(fileSize / partMaxSize);
    int parts = (int) Math.ceil(fileSize / partMaxSize);

    for(int i = 1; i < parts+1; i++)    {
        String partNumber = i + "";
        System.out.println("part: " + partNumber);
        int partSize = (int) (i < parts ? partMaxSize : fileSize);
        fileSize -= partSize;
        int tmp = 0;
        tmp = bis.read(buffer);
        url = String.format("https://www.site.com/upload/multipart/%s/%s", assetId, partNumber);

        final HttpPut request = new HttpPut(url);
        request.addHeader("Authorization", "Bearer " + accessToken);
        request.addHeader("Content-Type", "application/octet-stream");
        request.setEntity(new ByteArrayEntity(buffer));

        //Magical code start
        int hardTimeout = 5; // seconds
        TimerTask task = new TimerTask() {
            public void run() {
                if (request != null) {
        new Timer(true).schedule(task, hardTimeout * 1000);
        //Magical code end

        HttpResponse response = client.execute(request);

HTTPClient POST Hangs/Timeout Exception

Tag : chash , By : PatrickSimonHenk
Date : March 29 2020, 07:55 AM
like below fixes the issue For some reason the process could not be multithreaded.
Switched from Tasks to blocking single threaded it worked fine...

Re-using HttpClient but with a different Timeout setting per request?

Tag : .net , By : Yolanda N. Ceron
Date : March 29 2020, 07:55 AM
seems to work fine Under the hood, HttpClient just uses a cancellation token to implement the timeout behavior. You can do the same directly if you want to vary it per request:
var cts = new CancellationTokenSource();
await httpClient.GetAsync("http://www.google.com", cts.Token);
httpClient.Timeout = System.Threading.Timeout.InfiniteTimeSpan;

HttpClient getting timed out even after setting Timeout.Infinite

Tag : .net , By : omaidog
Date : March 29 2020, 07:55 AM
this will help I have tried following code for Android and iOS and it seems working and can wait little longer on socket while fetching data using webservice
in Xamarin.Android following code is used and exposed it using DependencyService
 public HttpClientHandler GetHttpClientHandler()

            Xamarin.Android.Net.AndroidClientHandler http = new Xamarin.Android.Net.AndroidClientHandler();
            http.ReadTimeout = TimeSpan.FromMinutes(5.0);   

            return http;
HttpMessageHandler IHttpHandler.GetHttpHandler()

    NSUrlSessionConfiguration sessionConfig = NSUrlSessionConfiguration.DefaultSessionConfiguration;
    sessionConfig.TimeoutIntervalForRequest = 300;
    sessionConfig.TimeoutIntervalForResource = 300;
    sessionConfig.WaitsForConnectivity = true;

    NSUrlSessionHandler sessionHandler = new NSUrlSessionHandler(sessionConfig);

    return (sessionHandler);
   HttpClient client = new HttpClient(DependencyService.Get<IHttpClientHandler>().GetHttpClient());
Related Posts Related QUESTIONS :
  • Invalid Resource File
  • Getting DirectoryNotFoundException when trying to Connect to Device with CoreCon API
  • How to wait for thread complete before continuing?
  • Is String.Format as efficient as StringBuilder
  • ASP.NET Web Service Results, Proxy Classes and Type Conversion
  • sgen.exe fails during build
  • In C#, why can't a List<string> object be stored in a List<object> variable
  • C# loop - break vs. continue
  • How to access .Net element on Master page from a Content page?
  • Why are unsigned int's not CLS compliant?
  • Why is Array.Length an int, and not an uint
  • How do I make event callbacks into my win forms thread safe?
  • Genealogy Tree Control
  • WCF Service - Backward compatibility issue
  • Binary patch-generation in C#
  • Tab Escape Character?
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com