View previous topic :: View next topic |
Author |
Message |
wielklem
Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
|
Posted: Fri Sep 10, 2021 10:26 am Post subject: http post data |
|
|
Hi all,
I'm strugeling with the http post in a simple website.
the coding is simple that writes the tcp data to putty:
Code: |
Tempw = Socketstat(i , Sel_recv) ' get received bytes
If Tempw > 0 Then ' if there is something received
Bcmd = 0
Do
Tempw = Tcpread(i , S)
print s ' read a line
'if MID(S , 1, 4) = "POST" then
'print s
end if
If Left(s , 3) = "GET" Then
Bcmd = 1
' GET /index.htm HTTP/1.1
End If
Loop Until S = "" ' wait until we get an empty line
|
the code for the site (mozilla sample code for testing):
Code: |
DATA "<form action={034}http://192.168.0.101{034} method="POST">"
DATA " <div>"
DATA " <label for="say">What greeting do you want to say?</label>"
DATA " <input name="say" id="say" value="Hi">"
DATA " </div>"
DATA " <div>"
DATA " <label for="to">Who do you want to say it to?</label>"
DATA " <input name="to" id="to" value="Mom">"
DATA " </div>"
DATA " <div>"
DATA " <button>Send my greetings</button>"
DATA " </div>"
DATA "</form>"
|
Wireshark shows 13 bytes send and within the putty debug I can see 13 bytes received:
But the content of the 13 bytes somehow get's lost.
At least, within the putty debug i can not find them again.
any suggestions?
thanks! |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5920 Location: Holland
|
Posted: Fri Sep 10, 2021 11:47 am Post subject: |
|
|
I dont get it. you do not post/write code in your sample. you only read data from the server.
But i do see that your DATA lines are not ok.
since you send a string, you need to use double quotes for bascom.
but the data you sent should not contain double quotes. the simplest way is to use single quotes since the browser will understand that as well.
other wise use {034} for each double quote.
one other way is to create a binary file that you send as is. Use the $INC to include it, then do not use tcpwritestr but tcpwrite. _________________ Mark |
|
Back to top |
|
|
wielklem
Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
|
|
Back to top |
|
|
wielklem
Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
|
Posted: Fri Sep 10, 2021 3:39 pm Post subject: |
|
|
I need to clear something up:
Only if I use the POST command the data get's lost.
If I for example use the GET command the input from the webpage is visible in debug because it is placed in the header:
Code: |
GET /favicon.ico HTTP/1.1
Host: 192.168.0.101
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: image/webp,*/*
Accept-Language: nl,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://192.168.0.101/?say=Hello+Mark&to=for+bascom+forum
Sec-GPC: 1
|
What I don't understand is why I can only read the header of the post command and not the body that contains the actual data. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5920 Location: Holland
|
Posted: Fri Sep 10, 2021 7:32 pm Post subject: |
|
|
i do not know what code you use but after reading the headers you get the size of the data.
then you need to read this data. but this is not string data : it can be any kind of data.
in the webserver sample this code is used:
Code: |
Elseif Left(s , 15) = "Content-Length:" Then ' for post
S = Mid(s , 16) : Bcontent = Val(s )
...
If Bcmd = 3 Then
#if Cdebug
Print "Posted data"
#endif
Tempw = Tcpread(i , Buf (1) , Bcontent ) ' read data
#if Cdebug
Bcontent = Bcontent + 1
Buf (bcontent ) = 0 ' put string terminator at end of data so we can handle it as a string
Print S
#endif
Shtml = "/redirect.htm" ' redirect to www.mcselec.com
End If
|
_________________ Mark |
|
Back to top |
|
|
wielklem
Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
|
Posted: Fri Sep 10, 2021 7:38 pm Post subject: |
|
|
albertsm wrote: |
but this is not string data : it can be any kind of data.
|
Whoops, that can indeed be the issue
i'm indeed only looking at strings, not 'any' kind of data.
something to do with a donkey and stone..
Thanks, I'll test!
once working I'll post the complete code into the 'share code' topic.
chears! |
|
Back to top |
|
|
wielklem
Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
|
Posted: Mon Oct 18, 2021 2:04 pm Post subject: |
|
|
I found the issue a day after my last post, but had no time to post it yet.
here it is:
Actually it is string data.
After implementing a bug (endless loop) I found the problem in the code.
The POST command contains two sets of data, the header and the body. The header I already could read, but the body containing the data from the page was not read.
And the issue was simple, the body starts with an empty line. And there is the issue.
The loop is stated as: "Loop until S = "" " so it breaks at the empty line. Therefor I could never read the actual data.
Simple but stupid as always. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5920 Location: Holland
|
Posted: Mon Oct 18, 2021 3:05 pm Post subject: |
|
|
i would not call it stupid but learning. _________________ Mark |
|
Back to top |
|
|
|