Forums Register Login

"Homemade" URL & URLConnection methods

+Pie Number of slices to send: Send
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.

1
+Pie Number of slices to send: Send
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.
1
+Pie Number of slices to send: Send
What classes are you allowed to use?
+Pie Number of slices to send: Send
 

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
1
+Pie Number of slices to send: Send
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.

We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 601 times.
Similar Threads
BufferedReader and Socket trouble
url reader applet
Please help for this Problem in creating excel sheet using java
port number
Networking question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:42:59.