Greetings,
I have a simple web server running in an atmega328P based on the sample web server code from the sample files. I'm using a WIZ810MJ module with the W5100 chip and using the latest Bascom 2.0.7.6. I'm attempting to read POSTed data from the browser. Like the sample, I'm using a DO LOOP to read the header information until I get to a blank line which signifies the end of the header info. According to the help file:
"When you use TCPread with a string variable, the routine will wait for CR + LF and it will return the data without the CR + LF.
For strings, the function will not overwrite the string."
"For example, your string is 10 bytes long and the line you receive is 80 bytes long, you will receive only the first 10 bytes after CR + LF is encountered.
Also, for string variables, you do not need to specify the number of bytes to read since the routine will wait for CR + LF."
My problem is that TCPREAD is not waiting for a CRLF until it returns data. Sometimes it returns a partial string before the CRLF. This does not cause a problem until the string returned is just before the CRLF. When this happens, the next TCPREAD sees just the CRLF and thinks that this is the end of the header. Here's a dump to a serial terminal demonstrating the problem:
Listening on socket : 1
sock_est
receive buffer size : 537
S=POST /index.html HTTP/1.1
S=Host: 192.168.0.137:5001
S=Connection: keep-alive
S= 7
S=Cache-Control: max-age=0
S=Accept: text/html,application/xhtml+xml,appl
S=ication/xml;q=0.9,image/webp,*/*;q=0.8
S=Origin: http://192.168.0.137:5001
S=User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW
S=64) AppleWebKit/537.36 (KHTML, like Gecko) C
S=hrome/32.0.1700.76 Safari/537.36
S=Content-Type: application/x-www-form-urlenco
S=ded
S=Referer: http://192.168.0.137:5001/index.htm
S=l
S=Accept-Encoding: gzip,deflate,sdch
S=Accept-Language: en-US,en;q=0.8
S=
Posted data
IP=1234
You can see that several of the header entries are split without waiting for the CRLF. The specific area where I encountered the problem is the 'Referer:" header. If I change the IP address to 192.168.0.37, then the TCPREAD ends just before the CRLF and the next TCPREAD sees the CRLF as a blank line and the end of the header. In that case my POSTed value ends up being "Accept-" which are the next 7 characters. Since this post is getting a little long and the code is in the sample file, I have left the code out of the post but, if necessary, I can certainly provide the relevant part of it.
I'm not sure if this is something I'm doing wrong, a bug, or my misunderstanding. Any help appreciated.
Thanks,
Bob
↧