I would like to know if is possible to identify (with JAVA) the kind of computer used to make a request, for example: Server, desktop, PDA (tablet,cellphone,etc)?
Thank you!
Depends on what are you using to accept requests. For http requests, informations are in User agent section of request header.
Yes it is to a degree. You have to get the User-Agent string from the HTTP request. How to do that will depend on your Java and framework implementation but that's the direction you should take. You will have to examin the string for browser versions, mobile, etc...
Here is the request from my Mac:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1
And here from my Windows server:
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
And here from my iPhone:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25
Related
I know that I had to search on Google, Youtube and Stackoverflow before I ask my question on Stackoverflow .
But I swear I watched many videos on Youtube, And I searched for many ways on google and Stackoverflow ! to solve my problem. ,
I can't get the full response,
And now i'm stuck with this,
Facebook checks for browser:
Add agent string to request:
String content1 = "GET /zuck HTTP/1.1\r\nHost: www.facebook.com\r\nuser-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36\r\n\r\n";
`Hi,
I am trying to get the user's browser information in my servlet filter. I used a simple code, see below.
String userAgent = request.getHeader("User-Agent");
User was using Google chrome, and what the above code printed is below.
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
It printed the names of all the major browsers instead of getting the once the app is running. what is wrong here?
Nothing is wrong here.
For example let us consider the returned string is
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36
Then the explanation is
ChromeChrome 41.0.2228.0
Mozilla ==>
MozillaProductSlice. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore
5.0 ==> Mozilla version
Windows NT 6.1 ==> Operating System Windows 7
AppleWebKit ==> The Web Kit provides a set of core classes to display web content in windows
537.36 ==> Web Kit build
KHTML ==> Open Source HTML layout engine developed by the KDE project
like Gecko ==> like Gecko...
Chrome Name ==> Chrome
41.0.2228.0 ==> Chrome version
Safari ==> Based on Safari
537.36 ==> Safari build
Description: Free open-source web browser developed by Google.
Chromium is the name of the open source project behind Google Chrome, released under the BSD license.
You can find more information in below link
http://www.useragentstring.com/pages/Chrome/
click on each link on the page to get more info
I'm developing a WebSocket server using Netty 4.0.21Final.
Before using Netty, I was sending data via socket directly and, now, I'm still doing the compression of the data by my self.
But, when looking closely at the HTTP Headers of my test client on Chrome browser, I saw this:
Request URL:ws://127.0.0.1:8089/echo
Request Method:GET
Status Code:101 Switching Protocols
Request Headers CAUTION: Provisional headers are shown.
Cache-Control:no-cache
Connection:Upgrade
Host:127.0.0.1:8089
Origin:null
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
Sec-WebSocket-Key:U0CPp11Bhqxp2lffj4tebw==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Response Headers
Connection:Upgrade
Sec-WebSocket-Accept:0vvWjhf27ScZauqx+jSfm/Xsuho=
Upgrade:websocket
The permessage-deflate on the Extensions section means that my messages are been compressed?
So, to try to answer this, I used a software called Wireshark and, when looking at the messages I could see that It was not compressed at all, they were all in plain text.
So, what do I must do to Netty really compress the messages for me?
Compression support was just added yesterday. So it is not included in any release yet:
https://github.com/netty/netty/commit/282d6e73b82ec943a739201f7be1985c45ef032b
I try to get webpage using HttpURLConnection, and get a result of mobile version page.
Now I want to get a desktop version page, and try to use: System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0"); or setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0"); But I still get a result of mobile version page.
Does anyone know how to get a desktop version source code of webpage instead the mobile version?
PS: My Android is 2.3.7
You have to set the User-Agent of your connection to pretend that it's a desktop client.
As you are using the HttpUrlConnection, you can do something like:
URL url = new URL( "http://www.google.co.in/" );
HttpUrlConnection connection = (HttpUrlConnection) url.openConnection();
connection.setRequestProperty( "User-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64)
I got the following information using request.getHeader("User-Agent") method inside a Servlet:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10
Actually what is the client browser?
It's Chrome 8.0.552.
This website may be useful for future consultations: http://user-agent-string.info. Paste the UA string there and click Analyze. They have even a XML-RPC webservice.