2

I am on windows and What is the easiest and fastest way to make a POST action to a URI? Can I achieve this with command line or PowerShell?

tugberk
  • 57,477
  • 67
  • 243
  • 335

3 Answers3

5

Powershell example:

 $c=New-Object System.Collections.Specialized.NameValueCollection
 $c.Add('param1','value1')
 $c.Add('param2','value2')
 $wc = New-Object system.net.webclient
 $d = $wc.uploadvalues("http://your.url",$c)
Andrei Schneider
  • 3,618
  • 1
  • 33
  • 41
3

How about using curl?

Explicit usage in your pespective is described here.

Sample POST usage below (extracted from the curl manual):

curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi
Community
  • 1
  • 1
nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • Thanks for the answer. looks like the easiest way. but how do I get the response back with this code? – tugberk May 05 '11 at 15:55
  • You could redirect the output using ">" into a file or a variable – nulltoken May 05 '11 at 16:28
  • I'll try that but I am now unable to find where the command line tool is on the web. I downloaded something but it ended up as source code. do u know where I can download that command line tool – tugberk May 05 '11 at 16:38
1

This is now native for PowerShell since version 3.0:

Invoke-WebRequest -method POST -uri http://somewhere.com/rest/sample -body $content

Aliased to iwr, wget and curl.

Saves all of the headache of creating a WebClient object.

According to Wikipedia:

PowerShell 3.0 is integrated with Windows 8 and with Windows Server 2012. Microsoft has also made PowerShell 3.0 available for Windows 7 with Service Pack 1, for Windows Server 2008 with Service Pack 1, and for Windows Server 2008 R2 with Service Pack 1.

Ray Hayes
  • 14,896
  • 8
  • 53
  • 78