none
Getting error on retrieving data from a url: Response status code does not indicate success: 999 (Request denied) RRS feed

  • Question

  • Hi,

    I am trying to retrieve data on a url via httpClient request but I am getting "Request denied" error. Below is the code of it.

     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
     httpClient.DefaultRequestHeaders.Add("AcceptLanguage", " en-US");
     httpClient.DefaultRequestHeaders.Add("Accept", " text/html, application/xhtml+xml, */*");
     httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0;Windows 7)");
     var response = httpClient.GetByteArrayAsync(url).Result;

    So, while retrieving response I am getting request denied error. Is there anything I need to change in my Request header?

    Thanks,

    Yugank Narula


    Tuesday, January 2, 2018 3:32 PM

All replies

  • This is really a question for the API provider. The error you're getting indicates they didn't like what you sent them. You should verify the data you're sending and what they expect. Note that you appear to be trying to emulate a browser which is probably not what you want to do for getting a byte array. If you're trying to work with an API then you won't be emulating a browser. Also note that you're trying to read a byte array but if you're requesting XML then it'll likely be text so you should read as a string or stream and then save into a file.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, January 2, 2018 3:54 PM
    Moderator
  • Hello Yugank,

    The "Request denied" issue is related to both server side and client side. Even if your client code is correct, the issue also will be possible to happen. Your code just set the request header "accept language", "Accept"(represent the type of data the client want to accept), "User Agent".

    Please try to use fiddle or postman other web capture tools to debug the request content and response content.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 3, 2018 6:43 AM
    Moderator
  • Hello Yugank,

    Is there any update or any other assistance I could provide? You could mark the helpful reply as answer if the issue has been solved. And if you have any concerns, please do not hesitate to let us know.

    Thank you for your understanding and patience!

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, January 28, 2018 12:23 PM
    Moderator