22

What is the simplest way of sending an HTTP POST to a localhost address/port under Windows?

E.g. do any browser plugins exist to do this or could a command be sent in the Chrome Developer Tools / Firebug console?

[Have seen similar q's asked before but the answers mostly seem to recommend the use of Unix tools such as CURL or Websites such as http://www.hurl.it, which preclude sending the request to localhost.]

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
  • After a few more minutes of searching I found a very similar q has actually been asked before [here](http://stackoverflow.com/questions/4797534/how-do-i-manually-fire-http-post-requests-with-firefox-or-chrome) so have voted to close. – Steve Chambers Jan 10 '14 at 14:04

3 Answers3

29

I use Advanced REST Client usually. I assume it works offline too(never tried it though as my Internet is always on).

Advanced REST Client for Chrome

I think the plugin is available for firefox too. Just google Advanced REST Client

EDIT:

Some other cool alternatives:

Paw (My current favourite)

Postman

hammergun
  • 448
  • 3
  • 8
6

if you use Chrome you can go with the DHC by Restlet or with Rest Console.

I think you can find extension like those for firefox too.

Filip
  • 3,002
  • 1
  • 26
  • 37
rollsappletree
  • 620
  • 1
  • 5
  • 14
4

I would invoke PHP with a script that does the post.

file send_post.php

<?php
// here I use argv for URL, but you can adapt it however you like
$url = "http://localhost/".$argv[1];
$data = array('var1' => 'value1', 'var2' => 'value2');

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)));

$response = file_get_contents($url, false, stream_context_create($options));

// you can echo the response if you're interrested, or just dump it
echo $response;
?>

test file http://localhost/SO/PHP/receive_post.php

<?php print_r ($_POST) ?>

invokation

C:\Dev\PHP\SO\PHP>php send_post.php whatever

Warning: file_get_contents(http://localhost/whatever): 
         failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
         in C:\Dev\PHP\SO\PHP\send_post.php on line 12

C:\Dev\PHP\SO\PHP>php send_post.php SO/PHP/receive_post.php
Array
(
    [var1] => value1
    [var2] => value2
)
kuroi neko
  • 8,479
  • 1
  • 19
  • 43
  • 2
    Well a batch file might be considered simpler than a GUI. It all depends of your definition of "simple" :). Maybe some other OPs will find that alternative more appealing, who knows? – kuroi neko Jan 10 '14 at 14:29