How to simulate HTTP POST on localhost (*Windows* not Unix)? [duplicate]
Asked Answered
J

3

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.]

Jada answered 10/1, 2014 at 13:54 Comment(1)
After a few more minutes of searching I found a very similar q has actually been asked before here so have voted to close.Jada
A
30

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

Anglin answered 10/1, 2014 at 14:0 Comment(0)
N
7

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.

Noheminoil answered 10/1, 2014 at 13:59 Comment(0)
S
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
)
Subphylum answered 10/1, 2014 at 14:21 Comment(1)
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?Subphylum

© 2022 - 2024 — McMap. All rights reserved.