Reading HTTP request using InputStream

B

Ben

Hi,

I'm using Inputstream to read an HTTP request from my browser (i'm
actually making a proxy).
The code:
InputStream in = new DataInputStream(socket.getInputStream());
ArrayList<Integer> byteArray = new ArrayList<Integer>();
int currByte=in.read();
while (currByte!=-1){ // Reading byte until -1 is reached
byteArray.add(new Integer(currByte));
System.out.print((char)currByte);
currByte = in.read();
}
For some reason, instead of recognizing the end of the request and
returning -1 InputStream.read() blocks forever.

Am i doing something wrong??
Thanks,
Ben.
 
F

Finomosec

Ben said:
Hi,

I'm using Inputstream to read an HTTP request from my browser (i'm
actually making a proxy).
The code:
InputStream in = new DataInputStream(socket.getInputStream());
ArrayList<Integer> byteArray = new ArrayList<Integer>();
int currByte=in.read();
while (currByte!=-1){ // Reading byte until -1 is reached
byteArray.add(new Integer(currByte));
System.out.print((char)currByte);
currByte = in.read();
}
For some reason, instead of recognizing the end of the request and
returning -1 InputStream.read() blocks forever.

Am i doing something wrong??
Thanks,
Ben.

See Thread: "writing a proxy ..."
news.online.de comp.lang.java.programmer:631136

There is more advanced code for a proxy.

There may be a EOT or EOF signal, that indicates the end of the stream.

But anyway you should implement a timeout in case the browser aborts the
request, or the connection is lost before end of the request/answer.

Maybe its better to take an existing Java-Proxy and modify it to your needs.

Maybe this can be used (found it on a quick google search):
http://simile.mit.edu/httptracer/index.html
This looks like the main proxy-class:
http://simile.mit.edu/repository/ht...u/mit/simile/tools/httptracer/Connection.java

Greetings Finomosec;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top