Jordan Cox
Jordan Cox

Reputation: 23

How to Set User-Agents in an HttpRequest (Unit Testing)

I've got a method that takes in an HttpRequest object and performs differently based on what User Agent is set. I'm trying to unit test it and am having a heck of a time tracking down how to set the User Agent string. I've tried the raw HttpRequest object and a variety of other objects that eventually yield it to no avail.

Does anyone have any idea how to set the user agent string for an HttpRequest object?

Thanks!

Upvotes: 1

Views: 1531

Answers (2)

Adam Ralph
Adam Ralph

Reputation: 29956

You can set the UserAgent property on an HttpWebRequest, are you able to use that type instead?

Upvotes: 1

Martin OConnor
Martin OConnor

Reputation: 3593

You probably need to use a mock HttpRequest object. This will allow you to set various properties so you can test how your webapp responds.

Upvotes: 0

Related Questions