WebClient Header

Peter Volz 1,295 Reputation points
2024-02-18T23:23:19.41+00:00

Hello experts

When using WebClient DownloadStringAsync or DownloadFileAsync or UploadValues do I need to add user-agent header?

If so what to set? I found this on some websites, OK?

WebClient.Headers.Add("user-agent", "Mozilla/5.0 (Compatible; MSIE 11.0; Windows NT 10.0; .NET CLR 4.0.30319)")

Not adding header can cause problem with some sites?

Thanks :)

Developer technologies | VB
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-02-19T10:00:25.0733333+00:00

    Hi @Peter Volz ,

    Some websites may expect a user-agent header to be present in the request, and not including one might result in unexpected behavior or rejection of the request.

    The user-agent header identifies the client making the request to the server. It helps the server understand what kind of client is accessing the resource and can be used by websites for various purposes like browser compatibility, analytics, and security.

    The user-agent string you provided looks fine. It mimics a typical user-agent string for a browser running on Windows 10 with Internet Explorer 11.0 and .NET CLR 4.0.30319.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.