0

The program just read form head and stops.

//...

Socket client = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

System.out.println("Request:");

while ((line = in.readLine()) != null)
    if (line.length() > 0)
    System.out.println("\t" + line);
        else break;

in.close();
client.close();

When I try to submit some form on browser:

Waiting for request...
Connection accepted.
Request:
    POST /form.php HTTP/1.1
    Host: x-x-x-x
    Connection: keep-alive
    Content-Length: 31
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://neviat.us.to
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
    Content-Type: application/x-www-form-urlencoded
    Referer: http://x-x-x-x
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Connection closed.

I got the Content-Length, but nothing about the content itself. ¬¬ I thougth that could be the else break;, so I took it off and tried again:

Waiting for request...
Connection accepted.
Request:
    POST /buy.php HTTP/1.1
    Host: x-x-x-x
    Connection: keep-alive
    Content-Length: 31
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://neviat.us.to
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
    Content-Type: application/x-www-form-urlencoded
    Referer: http://x-x-x-x
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4

    // stop here, waiting for stream...

But the content isn't there too.

How can I get it?

2 Answers 2

0

Change:

if (line.length() > 0)

to

if (line.length() > -1)

lines of 0 length are perfectly valid

Sign up to request clarification or add additional context in comments.

1 Comment

But even if I did not check it and print all I get, the content is not printed.
0

Change In code:

//...

Socket client = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

System.out.println("Request:");

while ((line = in.readLine()) != -1)
    if (line.length() > 0)
    System.out.println("\t" + line);
        else break;

in.close();
client.close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.