views:

250

answers:

2

I am developing a small embedded web server. I want to add parsing of post requests, but I am having a problem with input password fields from Chrome. Firefox and IE work perfectly.

The HTML:

<form action="start.webem" method="post"> 
<input value="START" type="submit" /><!--#webem start --> 

Password: <input type="password" name="yourname"  autocomplete="off" /> 
</form> 

From Firefox I get

POST /stop.webem HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://127.0.0.1:8080/
Content-Type: application/x-www-form-urlencoded
Content-Length: 13

yourname=test

However from Chrome, about 90% of the time, the yourname=test is missing

POST /start.webem HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
Referer: http://127.0.0.1:8080/
Content-Length: 13
Cache-Control: max-age=0
Origin: http://127.0.0.1:8080
Content-Type: application/x-www-form-urlencoded
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Though, occasionally it does work!!!

POST /start.webem HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
Referer: http://127.0.0.1:8080/start.webem
Content-Length: 13
Cache-Control: max-age=0
Origin: http://127.0.0.1:8080
Content-Type: application/x-www-form-urlencoded
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

yourname=test

I cannot find what causes it to work sometimes.

A: 

Probably because your HTML is so invalid. Fix that and your problems will disappear...

<form action="start.webem" method="post"> 
<input value="Start" type="submit" />

<p>
  <label for="yourname">Password:</label>
  <input id="yourname" name="yourname" type="password" autocomplete="off" />
</p>
</form>

To your comment:

HTML isn't technically case sensitive, but you should never ever use uppercase for tag/attribute names. That's just bad practice.

I think the reason it sometimes worked is because you had an open paragraph tag, but never closed it, so Chrome was probably sometimes placing the paragraph outside of your form.

Coronatus
I have noticed that Chrome is a lot more sensitive to html format than other browser, so I can believe that this is the problem.You seem to have converted everything to lower case, and surrounded the values with quotes. Is Chrome case sensitive!!!!Can you explain why it sometimes works?
ravenspoint
At a glance, it looks like it was valid HTML 5 before (not good HTML 5, but valid).
David Dorward
"fixing" the paragraph tags did not help. Neither did removing them all.
ravenspoint
Putting quotes around values and using lower case did not help. I have edited the original question to show the HTML I am now using.
ravenspoint
A: 

It is a chance that you didn't read the second portion of the data from the socket in your web server. That might describe why sometimes it is working.

loislo
This sounds plausible. Chrome splits the requests up?
ravenspoint
There is no guarantee to get all the sent data in one packet. The data can be fragmented at any level of network stack.1) browser can send the data by two separate calls of send function;2) OS network stack can split the data have been sent by one call into two packets because MTU limit;3) the same can happen on network devices like router etc;4) the two block of data can be joined inside network stack and sent as one packet.
loislo
Yes, this is the solution. It is strange that Chrome sends two packets, while FF and IE send one. However, it is obviously ( after reading loislo's comment ) better not to assume that there is just one packet. Once I rewrote my post parser to handle requests in multiple packets, then everything worked with all browsers. Thank you.
ravenspoint

related questions