3

I have done a simple web page in php to test post request from telnet. Here is the code of the web page (example.php):

<html>
<body>
<form method="post" action="example.php>">
Your Name:<input type="text" size="12" maxlength="12" name="Name"><br />
<input type="submit" value="submit" name="submit">
</form> 
<?php echo $_POST["Name"]; ?>
</body>
</html>

This works from the browser, but I would like to test it from telnet. I tried:

telnet localhost 80
POST example.php HTTP/1.0
Host: localhost
Content-Type: text/html; charset=iso-8859-1
Content-Length: 11

Name=myname

But it doesn't work....any help?

4
  • 3
    Either look at Fiddler or Wireshark and see what a real POST packet contains, or read the RFC a bit more deeply ;) Commented May 23, 2011 at 7:59
  • "But it doesn't work...." sorry, but this is not a good kind of error message. - tell us more about reactions and behavior of the system. check the webserver-access/error log, and so on. Commented May 23, 2011 at 8:02
  • yes, you are right...i will try to dig a bit deeper :) anyway the response from server was a HTTP/1.1 400 Bad Request Commented May 23, 2011 at 8:07
  • I'd recommend curl, which is a bit more user friendly for testing HTTP requests: curl http://localhost/example.php -d 'Name=myname' Commented May 23, 2011 at 8:12

2 Answers 2

4

Konerak is right. Take a look at a real request. For instance the Content-Type. I just gave it a try and got

Content-Type: application/x-www-form-urlencoded

You are also missing the second form field: your button. But I guess that does not matter...

Name=myname&submit=submit

take a look at http://en.wikipedia.org/wiki/POST_%28HTTP%29 for some more details and a good starting point for your research...

Update: try

POST /example.php HTTP/1.0
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 11

Name=myname

at least, this worked for me...

Sign up to request clarification or add additional context in comments.

Comments

2

change your content-type

POST /example.php HTTP/1.0
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 11

Name=myname

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.