Archived

This topic is now archived and is closed to further replies.

xqwww

[java] Java web server proxy problem

Recommended Posts

xqwww    122
Hello guys: I just wrote a simple web server proxy, it using socket port 8080 , and I set my web browser''s LAN proxy using my IP address and socket port according my code. my proxy accept the browser(client)''s URL request, then get this request to the real server. get the web page content back to the client as a respond message.. every things fine except the image display.. I wonder why cause this problem.. does anybody can tell me this reason? this is my server proxy code.. import java.io.*; import java.util.*; import java.net.*; class RealServerProxy { public static void main(String argv[]) throws Exception { String requestMessageLine,inputLine,temp=""; String URLstring; ServerSocket listenSocket=new ServerSocket(8080); Socket connectionSocket=listenSocket.accept(); //accept the client''s web request BufferedReader inFromClient=new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient=new DataOutputStream(connectionSocket.getOutputStream()); requestMessageLine=inFromClient.readLine(); StringTokenizer tokenizedLine=new StringTokenizer(requestMessageLine); if(tokenizedLine.nextToken().equals("GET")) { //get URL from the request message of client URLstring=tokenizedLine.nextToken(); System.out.println(URLstring); URL myURL = new URL(URLstring); BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream())); //get all web page content. while ((inputLine = in.readLine()) != null) temp+=inputLine; System.out.println(temp); //send all string to the client. outToClient.writeBytes(temp); in.close(); connectionSocket.close(); } else System.out.println("Bad Request Message"); } }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Images aren''t text. Don''t treat them like text, and the problem will disappear.

I suppose I could explain a BIT further... Quit using Readers and Writers. Use InputStreams and OutputSteams.

Share this post


Link to post
Share on other sites