3

What is the best way to do this? I tried to use a ServerSocket and change my proxy setting port to send all traffic to my Java program. Well, it connects but I can't seem to read the request with clientSocket.readLine().

I don't want to know how to make my code work though, which is why I won't post the code. I want to know what the best way would be to intercept the HTTP request for reading. I'm guessing I will take an approach changing the proxy port to redirect traffic to my app (Like programs like Burp Suite and WebScarab do).

So in other words, can someone give me an example or pseudo code on how Burp Suite/WebScarab would read HTTP requests just by changing the proxy port?

MrLolEthan
  • 76
  • 3
  • 9
  • I think you could try apache mina to implement an http proxy – Leo Feb 17 '14 at 20:12
  • Here's a Github repo for a simple Java proxy server: https://github.com/adamfisk/LittleProxy – Mike B Feb 17 '14 at 20:15
  • I don't want an actual proxy, just a way to read HTTP requests like Burp Suite or WebScarab. – MrLolEthan Feb 17 '14 at 20:18
  • And that's what I want. To read the HTTP request only. Also Mike B that is not what I am asking. – MrLolEthan Feb 17 '14 at 22:58
  • Not sure what libs you're using, but I'm trying to solve the same problem and came across this: https://jersey.java.net/documentation/latest/filters-and-interceptors.html#d0e9720 Interceptors sound like the pattern you're looking for? – Fred Jun 18 '15 at 00:35

1 Answers1

0

try this.. and never forget to configure your browser.

ServerSocket ss=new ServerSocket(8080);
   while(true){
   Socket s=ss.accept();
   BufferedReader sin=new BufferedReader(new InputStreamReader(s.getInputStream()));
   String l=sin.readLine();
   System.out.println(l);
   URL url = new URL("http://your_URL");
   URLConnection urlCon = url.openConnection();

   BufferedReader src=new BufferedReader(new InputStreamReader(urlCon.getInputStream()));
   String srst;
   while ((srst=src.readLine()) != null)
   System.out.println(srst); 
     }