Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

http post data

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> EASY TCP/IP
View previous topic :: View next topic  
Author Message
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 37
Location: the Netherlands

blank.gif
PostPosted: Fri Sep 10, 2021 10:26 am    Post subject: http post data Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5285
Location: Holland

blank.gif
PostPosted: Fri Sep 10, 2021 11:47 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 37
Location: the Netherlands

blank.gif
PostPosted: Fri Sep 10, 2021 12:31 pm    Post subject: Reply with quote

Hi Mark,

Actually I am sending data from the page to the AVR.
the first part in the debug is the POST, afer that the page reloads with the GET
here you can see what i've entered in the inputfield:



Somehow the data is received but I can not get it out of S:

Code:

 Tempw = Tcpread(i , S)
                 print s  
 


this is the input:



As you can see the 34 bytes are received, but are not printed:
Back to top
View user's profile
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 37
Location: the Netherlands

blank.gif
PostPosted: Fri Sep 10, 2021 3:39 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5285
Location: Holland

blank.gif
PostPosted: Fri Sep 10, 2021 7:32 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 37
Location: the Netherlands

blank.gif
PostPosted: Fri Sep 10, 2021 7:38 pm    Post subject: Reply with quote

albertsm wrote:

but this is not string data : it can be any kind of data.


Whoops, that can indeed be the issue Brick wall
i'm indeed only looking at strings, not 'any' kind of data.

something to do with a donkey and stone.. Smile
Thanks, I'll test!

once working I'll post the complete code into the 'share code' topic.

chears!
Back to top
View user's profile
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 37
Location: the Netherlands

blank.gif
PostPosted: Mon Oct 18, 2021 2:04 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5285
Location: Holland

blank.gif
PostPosted: Mon Oct 18, 2021 3:05 pm    Post subject: Reply with quote

i would not call it stupid but learning. Very Happy
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> EASY TCP/IP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum