File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Facebook.com unsupported browser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Facebook.com unsupported browser?" Watch "Facebook.com unsupported browser?" New topic
Author

Facebook.com unsupported browser?

Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 106
I just ran my custom Java simple web browser application with the following parameters: www.facebook.com / 80

The reply I receive from the server is:


HTTP/1.1 302 forced.302
Location: http://www.facebook.com/unsupportedbrowser
Content-Type: text/html; charset=utf-8
X-FB-Debug: ...
Connection: keep-alive
Content-Length: 0


SimpleWebBrowser.java code

What is the reason facebook.com does not accept my request? Is it because I did not send it the User-Agent HTTP header?
I am confused.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42360
    
  64
It probably misses some request headers that a "normal" browser sends, likely at least the User-Agent header, but possibly others, so it knows what to send back.

If you want to implement programmatic web access, I recommend the HtmlUnit library; it's the best IMO.


Ping & DNS - my free Android networking tools app
Ryan McClain
Ranch Hand

Joined: Nov 27, 2010
Posts: 106
Thanks for the recommendation.

I did a test request from my regular Chrome browser to facebook.com and I had a look at the headers. Then I copied all the headers with their content, prepended them with out.println(""); and re-ran my app.
At least I got a '400 bad request' page now instead of the dreadful 302 with Content-Length: 0. From what I read on wikipedia is that 302 means the HTTP 1.1 specification has not been met.

I'll look into this another time because it takes a lot of time to troubleshoot.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42360
    
  64
... prepended them with out.println("") ...

That only works on Windows, because only Windows uses CRLF in the println method - and CRLF is what HTTP needs. On Unix-ish OSes you'd need to send CRLF especially (and use print instead of println).

I'll look into this another time because it takes a lot of time to troubleshoot.

Use HtmlUnit. Seriously. It can even emulate Chrome, Firefox and IE should the distinction be necessary.
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 328
    
    6

Ryan McClain wrote:From what I read on wikipedia is that 302 means the HTTP 1.1 specification has not been met.

That is not correct. A 302 is used to redirect the client/browser to another location - usually based on factors such as user agent type, preferred/supported language, geographic location, server loading, etc. The new location is specified in the HTTP Location header.

For example, I am located in Vancouver. When I navigate to www.goggle.com, my browser is redirected to www.google.ca - most likely based on my location.

GET / HTTP/1.1
Host:
www.google.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,es;q=0.4,fr;q=0.2,ja;q=0.2


HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.ca/?gfe_rd=cr&ei=ghjAU_uPNuGV8QfCzYDAAQ
Content-Length: 258
Date: Fri, 11 Jul 2014 17:01:54 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic
 
 
subject: Facebook.com unsupported browser?