Link to home
Create AccountLog in
Java

Java

--

Questions

--

Followers

Top Experts

Avatar of Absente
Absente

Java HTTP Web Server Post Request
Hi I am triying to develop HTTP web server which will response post request.

I am reading request like tihs.

while (true) {
                    String misc = br.readLine();
                    System.out.println("=====> " + misc);
                    if (misc==null || misc.length()==0)
                        break;                
                }

It can print messages from browser.

Like this.

=====> POST /mypage.html HTTP/1.1
=====> Host: 127.0.0.1:8080
=====> Connection: keep-alive
=====> Content-Length: 36
=====> Cache-Control: max-age=0
=====> Origin: http://127.0.0.1:8080
=====> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
=====> Content-Type: application/x-www-form-urlencoded
=====> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
=====> Referer: http://127.0.0.1:8080/mypage4.html
=====> Accept-Encoding: gzip,deflate,sdch
=====> Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4
=====> Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.3

But there is  no post datas ?

I am lokin for like this.
name=J.Doe&email=abuse%40spamcop.com

Why i cat get the data ?.

My form code

<form method="post" enctype="application/x-www-form-urlencoded; charset=UTF-8">

                        <input name="name" type="text" /><input name="email" type="text" /><input name="Submit1" type="submit" value="gönder" /></form>


Where is the problem.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rrzrrz🇺🇸

A blank line is sent between headers and data. See  
http://developers.sun.com/mobility/midp/ttips/HTTPPost/     

Avatar of AbsenteAbsente

ASKER

Thanks. How can I read after blank line.
The bufferedReader waiting on the blank line.

I try like this.
but I cant do this.


currentLine = br.readLine();
                List.add(currentLine);
                StringTokenizer methToken = new StringTokenizer(currentLine, " ");
                Method = methToken.nextToken();
                actionPage = methToken.nextToken();
                System.out.println("Method Type : " + Method);
                System.out.println("Actions Page : " + actionPage);

                while (true) {
                    currentLine = br.readLine();
                   
                    if (currentLine == null || currentLine.trim().length() == 0) {
                        if (Method.toUpperCase().equals("POST")) {
                            br.skip(1);
                            currentLine = br.readLine();
                            System.out.println("=====> " + currentLine);
                            List.add(currentLine);
                        }
                        else {
                            break;
                        }
                    }
                    else{
                    System.out.println("=====> " + currentLine);
                    List.add(currentLine);
                    }

                }

How can i read after the balnk line ?

ASKER CERTIFIED SOLUTION
Avatar of rrzrrz🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

SOLUTION
Avatar of AbsenteAbsente

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of AbsenteAbsente

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for Absente's comment http:/Q_27488267.html#37271819
Assisted answer: 100 points for rrz@871311's comment http:/Q_27488267.html#37269638
Assisted answer: 0 points for Absente's comment http:/Q_27488267.html#37269714

for the following reason:

thanks

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of rrzrrz🇺🇸

I answered the question. I should get the full 500 points.
Java

Java

--

Questions

--

Followers

Top Experts

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.