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?
Asked
Active
Viewed 343 times
3 Answers
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
-
$d is a byte array containing the body of the response from the resource. – Andrei Schneider May 05 '11 at 15:53
3
-
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
-
-
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