RawFocus RawFocus - 1 month ago 10x
PowerShell Question

POSTing Form Fields with Same Name in Powershell

I am looking to emulate a POST request using Powershell (v4). Fiddler has enabled me to replicate the original in all relevant aspects other than the following:

example of multiple form fields with same name

I have tried a number of approaches, the easiest to explain / demonstate is probably:

invoke-webrequest -Uri "$uri" `
-body @{
} -method post -usedefaultcredentials

This gives the error:

Duplicate keys 'SASControlTable' are not allowed in hash literals.

How do I submit multiple fields with the same name using Powershell?


My actual http body looks like this:


Submitting an identical body with Powershell does not give me two parameters for
in the WebForms tab of fiddler (and only the second parameter is received by the web server). This is the issue I am trying to solve..


how about using "here strings"?

$body = @"

invoke-webrequest -Uri $uri -body $body -method post -usedefaultcredentials

PS you may or may not need double quotes

PPS most probably the above wont work - have a look at Fiddler's "Raw" tab and replicate the request body in $body

PPPS or you can make a request, get the forms/fields, populate them and make another request. Have a look at the help

Get-Help Invoke-WebRequest -ShowWindow



$body = '_program=%2FWeb%2Fstorm&_debug=0&_service=default&SASControlTable=%5B%7B%22colName%22%3A%22ACTION%22%2C%22colType%22%3A%22string%22%2C%22colLength%22%3A14%7D%5D&SASControlTable=%5B%7B%22ACTION%22%3A%22INITIALISATION%22%7D%5D'

(Invoke-WebRequest https://httpbin.org/post -Method Post -Body $body).content

in Posh:

  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "SASControlTable": [
    "_debug": "0", 
    "_program": "/Web/storm", 
    "_service": "default"
  "headers": {
    "Content-Length": "224", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.14393.82"
  "json": null, 
  "origin": "", 
  "url": "https://httpbin.org/post"

and in Fiddler

enter image description here

seems just like what you get to me