Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"Homemade" URL & URLConnection methods  RSS feed

 
C Johnston
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long of the short, I need to make an HTTP proxy that works with GET requests but I am not allowed as per the professor to use the built in java classes to do it. My code below is working perfectly with the built in methods.. but I can't use it. Can anyone help me think of a "homemade" solution to replace the sections of code separated (roughly) by comments. I've been working on this for hours but I am beyond stuck on what to do.

 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that the professor wants you to use a Socket to connect to the server via port 80 -- but Socket is part of the standard API too so maybe not. But I'm loath to believe that they want you to write your own class which uses native methods (also written by you in some other language) to connect to an external server, though, so maybe Socket is what you're supposed to use. You could ask the prof, I suppose.

Then you'd have to study up on the HTTP protocol and find out how to send a GET request via that Socket and (I presume) read the HTTP response you get back.
 
Norm Radder
Rancher
Posts: 1904
26
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What classes are you allowed to use?
 
C Johnston
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:What classes are you allowed to use?


I can use Socket and ServerSocket, the only classes I cannot use are URL and URL Connection
 
Mark Kitchell
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back in the dark ages when java was barely version 1, I would do this with an InputStreamReader and OutputStreamWriter from the socket.  Then you read/write the MIME protocol (see RFC 2045 and 2046 and all the RFC it references - interesting read to realize how simple MIME/HTTP really is).

If you don't have to support any specific mime types and all you want is the connection for GET:

Here's a link from stack overflow that puts it simply: http://stackoverflow.com/questions/10673684/send-http-request-manually-via-socket

Really short answer: all you need is a connection then the first thing down the connection is your GET request line terminated with CR/LF and that's all there is to it.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!