Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URLConnection vs socket

807580Jan 5 2010 — edited Jan 5 2010
I am just wondering what could be the difference in the results of the following two approaches. I am trying to load a web page from www.oanda.com. One approach is to read from the input stream associated with URLConnection object. Another one is to use socket and send the following request to
the server
GET /  HTTP/1.1
User-Agent: Simple Web Client
Host: localhost
Content-type: text/html
Connection: close
Content-length: 0
Accept: */*
The first one loads the page correctly while the second one returns just <HTML><HEAD></HEAD><BODY></BODY></HTML>. The pages from other servers that I've tried are loaded correctly. Therefore this is probably something specific to the server. I am wondering what could be the difference between the two approaches. (The ultimate objective is to send POST requests using socket thus any suggestions how to fix the socket are very welcome).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2010
Added on Jan 5 2010
20 comments
2,309 views