Reading HTTP request using InputStream

Discussion in 'Java' started by Ben, Feb 16, 2006.

  1. Ben

    Ben Guest

    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.
     
    Ben, Feb 16, 2006
    #1
    1. Advertising

  2. Ben

    Finomosec Guest

    Ben schrieb:
    > 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;
     
    Finomosec, Feb 16, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    2,194
    John Saunders
    Oct 16, 2003
  2. karahan celikel

    changing Request.InputStream

    karahan celikel, Mar 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,573
    Karahan Celikel
    Mar 4, 2004
  3. R
    Replies:
    5
    Views:
    2,149
    Kevin McMurtrie
    Mar 13, 2005
  4. Replies:
    8
    Views:
    1,117
    Roedy Green
    Feb 14, 2006
  5. deepak

    Request.InputStream

    deepak, Feb 13, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    835
    deepak
    Feb 13, 2008
Loading...

Share This Page