locked
HttpClient (Windows.Web.Http) stop automatic retry.

    Question

  • Hello, is it possible to prevent HttpClient from retrying to send a request after receiving 401 response? Is there some kind of retry policy filter that can be used?
    Tuesday, January 27, 2015 3:23 PM

Answers

  • You should be able to do so by simply disabling HttpBaseProtocolFilter.AllowUI and not setting any HttpBaseProtocolFilter.ServerCredential.

    HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
    filter.AllowUI = false;
    HttpClient client = new HttpClient(filter);
    var response = await client.GetAsync(uri);
    Debug.WriteLine(response);
    

    Tuesday, January 27, 2015 7:08 PM

All replies

  • You should be able to do so by simply disabling HttpBaseProtocolFilter.AllowUI and not setting any HttpBaseProtocolFilter.ServerCredential.

    HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
    filter.AllowUI = false;
    HttpClient client = new HttpClient(filter);
    var response = await client.GetAsync(uri);
    Debug.WriteLine(response);
    

    Tuesday, January 27, 2015 7:08 PM
  • Thank you very much - it worked. I was aware of "AllowUI" property but description in HttpBaseProtocolFilter class reference says:

    "Get or set a value that indicates whether the HttpBaseProtocolFilter can prompt for user credentials when requested by the server." 

    That's why I didn't think setting it to true would help in my case. Anyway thanks for your very fast reply!


    • Edited by kbagi Wednesday, January 28, 2015 10:01 AM
    Wednesday, January 28, 2015 10:00 AM