+3  A: 

The HTTP specification states that all clients are supposed to sent User-Agent headers. It however, does not state that they should identify the client in the manner a server wishes to. Android therefore complies with the specification, and there is not a lot you can do about it.

The best you could do is to use the setRequestProperty() method to attempt to get a preferable user-agent value in the request. There are no guarantees that it would work, but it is likely. The method needs to be called in the following manner:

connection.setRequestProperty("User-Agent","<em>USER-AGENT VALUE</em>");

Edit

Android uses WebKit. If you want to set WebKit's user-agent string, you'll either have to use a static value, or read the user-agent string from WebKit. I haven't attempted this, but the WebKit user-agent string is available in Android via the getUserAgentString() method of the WebSettings class.

Vineet Reynolds
I know about this, but how i can use the same type of connection string that the browser is using? I don't want to hardoced a user-agent myself, i want to use the device user-agent.
Lucas S.
I've updated the answer to include a possible solution.
Vineet Reynolds
@answer: The HTTP spec uses the word "should" not "must". This indicates that it would be nice, but you aren't "supposed" to.@Lucas S: Why would you want to identify yourself as the browser when you AREN'T the browser?
fiXedd
Nice to know that. Didnt know a separate RFC existed for that purpose.
Vineet Reynolds
I need to do this so my server can identify which device is sending the request. I attached some pics with the output i get when connecting with the browser and by code.
Lucas S.
A: 

it's be wrong if HttpURLConnection faked the user agent of the browser. it's not the browser after all. it would be nice if it sent a little more information, like maybe "Java/1.6 (MacOS 10.5 ..." etc.

Jeffrey Blattman