[java] Java web server proxy problem

Started by
1 comment, last by xqwww 20 years, 2 months ago
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"); } }
Game is my Dream
Advertisement
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.
yes.. I should use data input output instead..
Game is my Dream

This topic is closed to new replies.

Advertisement