4

In my application I make a few POST requests. I would like to simulate the client default browser user-agent because some websites make the most absurd checks.

Right now I just have a static one like this:

request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"); 

How can I make this dynamic?

7
  • What do you mean by dynamic? Commented Dec 31, 2013 at 4:37
  • @LaszloPapp The application should make requests with the same User-Agent of the default browser that the user has installed. Commented Dec 31, 2013 at 4:40
  • Which operating system? Commented Dec 31, 2013 at 4:42
  • @LaszloPapp I'm not sure if it is worth it. All the solutions I came-up with involve opening the default browser, wish wouldn't be good. Just looking for some ideas. OS, mainly Windows. Commented Dec 31, 2013 at 4:52
  • You could probably do some eavesdropping as the last resort, at least, but that is not a "nice" way of doing it. :) Commented Dec 31, 2013 at 4:55

1 Answer 1

3

Can you use windows API ObtainUserAgentString?

HRESULT ObtainUserAgentString( _In_ DWORD dwOption = 0, _Out_ LPCSTR *pcszUAOut, _Out_ DWORD *cbSize ); 

http://msdn.microsoft.com/en-us/library/ms775114(v=vs.85).aspx

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting. I will test it and get back.
Looks like this only works to get really old Internet Explorer user agent strings, not the user agent of the user's current default browser.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.