Can PINK receive and process HTTP POST requests?
Sapphire
Posts: 496
I have a HAN device that sends information via HTTP POST requests, and I'd like to capture and process them with my PINK module so that a Stamp or Prop can read the data variables serially. Does anybody know if this is possible?
I have been able to configure the HAN device to send the HTTP POST request to the IP of the PINK, and it seems happy doing so as it says it successfully connected to the PINK, and the data activity LED on the PINK flashes as each packet is sent (about once every 10 seconds).
But what I don't know how to do is write a script for the PINK to capture the HTTP POST request, strip out the data I want and put it in the serially accessible variables. Any suggestions on how to do this would be appreciated.
I have been able to configure the HAN device to send the HTTP POST request to the IP of the PINK, and it seems happy doing so as it says it successfully connected to the PINK, and the data activity LED on the PINK flashes as each packet is sent (about once every 10 seconds).
But what I don't know how to do is write a script for the PINK to capture the HTTP POST request, strip out the data I want and put it in the serially accessible variables. Any suggestions on how to do this would be appreciated.
Comments
[HTML]<html>
<form method="post" action="test.htm"
<p>
What value would you like to store in variable 01?
<input name="Nb_var01" type="text" maxlength="64">
<input type="submit" value="Accept">
</p>
</form>
</html>
[/HTML]
This file was called, test2.htm and once you post the value it loads test.htm which displays the value (see below).
[HTML]<html>
The value in variable 01 is: <Nb_var01>
</html>
[/HTML]
send/update multiple variables at the same time from a form.
The downside from the BASIC Stamp side is that the variable
which shows the Last Update variable will only indicate the
last one updated before the submit. So in this case it will
read 03, since variable 03 is the last one being updated.
There is no way to detect that multiple variables were updated
using this method without using another register as part of
the update. For example, you could force another register to
value when this form is submitted and then check that register
to determine that multiple values were updated.
[HTML]<html>
<body>
<FORM method="post">
<P>
What value would you like stored in these variables?</P>
<P>
01 <INPUT name="Nb_var01" type="text" size="75" maxlength="64"></P>
<P>
02 <INPUT name="Nb_var02" type="text" size="75" maxlength="64"></P>
<P>
03 <INPUT name="Nb_var03" type="text" size="75" maxlength="64"></P>
<P>
<INPUT type="submit" value="Send">
</P>
</FORM>
</html>[/HTML]
[HTML]<html>
<body>
<FORM method="post">
<P>
What value would you like stored in these variables?</P>
00 <INPUT name="Nb_var00" type="text" size="75" maxlength="64"> <br>
01 <INPUT name="Nb_var01" type="text" size="75" maxlength="64"> <br>
02 <INPUT name="Nb_var02" type="text" size="75" maxlength="64"> <br>
03 <INPUT name="Nb_var03" type="text" size="75" maxlength="64"> <br>
04 <INPUT name="Nb_var04" type="text" size="75" maxlength="64"> <br>
05 <INPUT name="Nb_var05" type="text" size="75" maxlength="64"> <br>
06 <INPUT name="Nb_var06" type="text" size="75" maxlength="64"> <br>
07 <INPUT name="Nb_var07" type="text" size="75" maxlength="64"> <br>
08 <INPUT name="Nb_var08" type="text" size="75" maxlength="64"> <br>
09 <INPUT name="Nb_var09" type="text" size="75" maxlength="64"> <br>
10 <INPUT name="Nb_var10" type="text" size="75" maxlength="64"> <br>
11 <INPUT name="Nb_var11" type="text" size="75" maxlength="64"> <br>
12 <INPUT name="Nb_var12" type="text" size="75" maxlength="64"> <br>
13 <INPUT name="Nb_var13" type="text" size="75" maxlength="64"> <br>
14 <INPUT name="Nb_var14" type="text" size="75" maxlength="64"> <br>
15 <INPUT name="Nb_var15" type="text" size="75" maxlength="64"> <br>
16 <INPUT name="Nb_var16" type="text" size="75" maxlength="64"> <br>
17 <INPUT name="Nb_var17" type="text" size="75" maxlength="64"> <br>
18 <INPUT name="Nb_var18" type="text" size="75" maxlength="64"> <br>
19 <INPUT name="Nb_var19" type="text" size="75" maxlength="64"> <br>
20 <INPUT name="Nb_var20" type="text" size="75" maxlength="64"> <br>
<script type="text/javascript">
var d="<Nb_var00>"
</script>
21 <INPUT name="Nb_var21" value=d size="75" maxlength="64"> <br>
22 <INPUT type=checkbox value="<Nb_var22>"> <br>
23 <INPUT type="radio" name="Nb_var23"> <br>
<P>
<INPUT type="submit" value="Send">
</P>
</FORM>
</html>[/HTML]
I've looked at your examples to see what they do. It appears they allow a user to enter values into the variables and then post them to the PINK. I ran the example HTM files to test that.
But in my situation, there will be no browser connected to the PINK, only the HAN web server which is sending HTTP POST requests (sort of like a HTTP GET request with a payload). So I need to capture this incoming HTTP stream, and pick out the data from it (which is in XML fragments as plain text). I don't know much about scripting or HTML, and am not sure where to start. Or if it's even possible to do this with the PINK. Any ideas?
I would take a look at the way the browser handles the request to post the data when post button is pressed on one of the examples I sent. Then you can try taking the button out of the equation and submitting the request without the source web page.
To elaborate on that, if you look at the way the URL is formed when making certain requests or submitting certain information, you'll notice it often contains the information necessary to process the request/submission. I have used this trick in the past to make automated queries to certain sites, such as IP address lookups.