When adding a header like this
restClient.AddHeader("User-Agent","My-User-Agent")
the RestClient will overrule this with the default "RestSharp 1.x.x.x" like is discussed in this issue. Can this be fixed, so that in the future, people will not be weirded out, when they need to set the User-Agent and it doesn't do anything? ;)
i'll see what can be done to allow the user content to remain and not get overridden.
@newnottakenname to set the user-agent, please use RestClient.UserAgent
instead:
RestClient.UserAgent = "test_user_agent";
(where RestClient is an instance of RestClient)
Although I agree that it is best practice to use OOP to set an User-Agent, instead of adding a header, I believe that adding a header should always overrule the user agent or at least give a warning to tell the programmer that the header has no effect on the actual User-Agent. It took me 2 weeks to figure out that nothing was being changed. I would like to prevent future programmers this problem.
To add to this, we have a requirement that the User agent is changed for almost every request made out, we re-use the Restsharp client instance across many threads, so setting the header for the individual request feels like the right way to go here.
Also, if you are blowing away a value I have set, throw an exception stating I can't set the property, rather than silently replacing it.
client.AddDefaultHeader
seems working for me, maybe you can switch to this method
Most helpful comment
@newnottakenname to set the user-agent, please use
RestClient.UserAgent
instead:(where RestClient is an instance of RestClient)