How does a POST header work?
Rforbes
Posts: 281
Hey all,
As usual, I've learned a lot from this forum and continue to try and learn new things.
I'm currently trying to work out an issue using POST with my spinneret. I'm not using Mike's HTTPServer for this, because it's an endeavor to learn, not to produce something valuable.
I've got a form made on a server...
And I'm attempting to connect to the server and send a POST header with the name/value pairs for the form. The idea is to automatically fill in the form with the spinneret.
My POST header is being created from my DAT section and looks like this:
Once I put this into the txdata buffer, I then calculate the "Content-Length" of the name/value pairs and convert that value to a string. Then I put that into the txdata buffer.
Then, I put my name/value pairs into the buffer and xmit..
In a nut shell, my txdata buffer looks like the following:
When I look at the response, I get the following:
I think my problem is how I'm forming my name/value pairs..... I have no clue how to force the "submit" button to "submit" and I'm not sure I've formed up the name/value pairs correctly.
Can someone show me what should be sent here???
Thanks much!
Robert
As usual, I've learned a lot from this forum and continue to try and learn new things.
I'm currently trying to work out an issue using POST with my spinneret. I'm not using Mike's HTTPServer for this, because it's an endeavor to learn, not to produce something valuable.
I've got a form made on a server...
<form action="connect.php" method="post"> <div><label for="thename"> Name Value: <input type="text" name="thename" id="thename"></label> </div> <div><input type="submit" value="submit"></div> </form>
And I'm attempting to connect to the server and send a POST header with the name/value pairs for the form. The idea is to automatically fill in the form with the spinneret.
My POST header is being created from my DAT section and looks like this:
Post_Hdr byte "Post /test.php HTTP/1.1 200 OK",13,10, { } "Keep-Alive: 300",13,10, { } "Host: rcc.cfbtechnologies.com",13,10, { } "User-Agent: Wiz5100",13,10, { } "Cache-Control: public",13,10, { } "Connection: keep-alive",13,10, { } "Content-Type: application/x-www-form-urlencoded",13,10,{ } "Content-length: ",0 { }
Once I put this into the txdata buffer, I then calculate the "Content-Length" of the name/value pairs and convert that value to a string. Then I put that into the txdata buffer.
Then, I put my name/value pairs into the buffer and xmit..
In a nut shell, my txdata buffer looks like the following:
Post /test.php HTTP/1.1 200 OK Keep-Alive: 300 Host: rcc.cfbtechnologies.com User-Agent: Wiz5100 Cache-Control: public Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-length: 25 thename=xxx&action=submit
When I look at the response, I get the following:
HTTP/1.1 200 OK Date: Wed, 10 Apr 2013 23:06:00 GMT Server: Apache Vary: Accept-Encoding Content-Length: 210 Keep-Alive: timeout=2, max=100 Connection: Keep-Alive Content-Type: text/html <form action="connect.php" method="post"> <div>< label for="thename"> Name Value: <input type=" text" name="thename" id="thename"></label> </div > <div><input type="submit" value="submit"></div > </form>
I think my problem is how I'm forming my name/value pairs..... I have no clue how to force the "submit" button to "submit" and I'm not sure I've formed up the name/value pairs correctly.
Can someone show me what should be sent here???
Thanks much!
Robert
Comments
If the response does not contain the name value pairs, I would suspect your PHP script is not doing what you expect. Post your PHP script.
I'd get the PHP stuff woring with your browser before trying this with the Spinneret. That way you can remove some of the moving parts.
This is the file I'm trying to post to with the spinneret. test.php (I already posted it above, but here it is again.)
Here is the connect.php that the file above posts to once the form is "submitted."
and the only other file involved is the output.html.php file which is:
When I go to test.php on my server, it renders as expected. I enter a value for thename and click the submit button, and it calls connect.php which then updates the database by inserting a new record into it's table. Works great, no issues at all.
When I try to use the spinneret to post to the test.php file, I get what I showed above.
If I try to just post to the connect.php file instead, I get an error telling me that "thename" cannot be null. So I'm thinking it's something to do with my POST header on the spinneret but I'm pretty much at a loss at this point.
The header looks find but there could a problem I do not see. I would do something pretty simple. Create a new page called posttest.php. Then simply render form data back to the Spinneret; echo "data =: " . $_POST;.
Consider downloading Fiddler. It's a great and free HTTP debugging tool which lets you see http headers. BTW, for quick header views I use Firefox and the HttpFox plugin. Take a look at the working code and use it as a template.
Thanks for the pointers! I installed the HttpFox plugin and by looking at the headers I was able to modify the spinneret header appropriately. Seems that by adding ""Accept: text/html" to my header it's working fine now. I wish I could find a concise reference to all the junk that can be put into a header, with descriptions and definitions of what each piece does.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
How browsers deal with the information is another discussion.
C'mon man.... I sent "concise reference" not "mental torture device" ya know?