简体   繁体   中英

Http Request and Response is not returning anything

I'm trying to write proxy server on localhost with port 8080 using just ServerSocket and Socket. I just want to see TEXT from website. I have created HTTP Request and i'm not sure if it's written good. The problem is with HTTP Response from a server, beacuse it's not returning anything. But first i want to know if request is good.

Then in Thread i'm just Reading request and sending it to a server:

BufferedReader fromClient = new BufferedReader(new InputStreamReader(socket.getInputStream());
HttpRequest req = new HttpRequest(fromClient);
Socket server = new Socket(req.getHost(), req.getPort());
DataOutputStream toServer = new DataOutputStream(server.getOutputStream());
toServer.writeBytes(req.toString());

Let's break this problem into several parts:

  1. Please provide more details in question asked like Are you creating only HTTP proxy? Do you have a website which only serves text aka which website are you testing your proxy against?
  2. Check whether your server is actually running properly. Open terminal and type wget website_name_here . This will tell you if there's a configuration problem in server itself. This will confirm if HTTP response coming from server is good enough.
  3. Check whether HTTP Request lacks something. Install Wireshark and capture outbound HTTP packet, then check if your HTTP Request is missing something. Wireshark should automatically flag anything missing. You may learn more about HTTP Response here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM