在 Powershell 中发布具有相同名称的表单字段
POSTing Form Fields with Same Name in Powershell
我希望使用 Powershell (v4) 模拟 POST 请求。 Fiddler 使我能够在除以下以外的所有相关方面复制原件:
我尝试了很多方法,最容易解释/演示的可能是:
invoke-webrequest -Uri "$uri" `
-body @{
_program='/Web/storm'
SASControlTable='[{"Name":"COL1","Type":"str"},{"Name":"COL2","Type":"str"}]'
SASControlTable='[{"COL1":"VAL1","COL2","VAL2"}]'
} -method post -usedefaultcredentials
这给出了错误:
Duplicate keys 'SASControlTable' are not allowed in hash literals.
如何使用 Powershell 提交同名的多个字段?
编辑:
我的实际 http 正文如下所示:
_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
使用 Powershell 提交相同的正文不会在 fiddler 的 WebForms 选项卡中为 SASControlTable
提供两个参数(Web 服务器仅接收第二个参数)。这是我要解决的问题..
使用 "here strings" 怎么样?
$body = @"
_program='/Web/storm'
SASControlTable='[{"Name":"COL1","Type":"str"},{"Name":"COL2","Type":"str"}]'
SASControlTable='[{"COL1":"VAL1","COL2","VAL2"}]'
"@
invoke-webrequest -Uri $uri -body $body -method post -usedefaultcredentials
PS
你可能需要也可能不需要双引号
PPS
上面的方法很可能不起作用 - 查看 Fiddler 的 "Raw" 选项卡并在 $body
中复制请求正文
PPPS
或者您可以发出请求,获取 forms/fields,填充它们并发出另一个请求。看看帮助
Get-Help Invoke-WebRequest -ShowWindow
PPPPS
这个
$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
时髦:
{
"args": {},
"data": "",
"files": {},
"form": {
"SASControlTable": [
"[{\"colName\":\"ACTION\",\"colType\":\"string\",\"colLength\":14}]",
"[{\"ACTION\":\"INITIALISATION\"}]"
],
"_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": "94.72.189.16",
"url": "https://httpbin.org/post"
}
在 Fiddler 中
看起来就像你给我的一样
我希望使用 Powershell (v4) 模拟 POST 请求。 Fiddler 使我能够在除以下以外的所有相关方面复制原件:
我尝试了很多方法,最容易解释/演示的可能是:
invoke-webrequest -Uri "$uri" `
-body @{
_program='/Web/storm'
SASControlTable='[{"Name":"COL1","Type":"str"},{"Name":"COL2","Type":"str"}]'
SASControlTable='[{"COL1":"VAL1","COL2","VAL2"}]'
} -method post -usedefaultcredentials
这给出了错误:
Duplicate keys 'SASControlTable' are not allowed in hash literals.
如何使用 Powershell 提交同名的多个字段?
编辑:
我的实际 http 正文如下所示:
_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
使用 Powershell 提交相同的正文不会在 fiddler 的 WebForms 选项卡中为 SASControlTable
提供两个参数(Web 服务器仅接收第二个参数)。这是我要解决的问题..
使用 "here strings" 怎么样?
$body = @"
_program='/Web/storm'
SASControlTable='[{"Name":"COL1","Type":"str"},{"Name":"COL2","Type":"str"}]'
SASControlTable='[{"COL1":"VAL1","COL2","VAL2"}]'
"@
invoke-webrequest -Uri $uri -body $body -method post -usedefaultcredentials
PS 你可能需要也可能不需要双引号
PPS 上面的方法很可能不起作用 - 查看 Fiddler 的 "Raw" 选项卡并在 $body
中复制请求正文PPPS 或者您可以发出请求,获取 forms/fields,填充它们并发出另一个请求。看看帮助
Get-Help Invoke-WebRequest -ShowWindow
PPPPS
这个
$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
时髦:
{
"args": {},
"data": "",
"files": {},
"form": {
"SASControlTable": [
"[{\"colName\":\"ACTION\",\"colType\":\"string\",\"colLength\":14}]",
"[{\"ACTION\":\"INITIALISATION\"}]"
],
"_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": "94.72.189.16",
"url": "https://httpbin.org/post"
}
在 Fiddler 中
看起来就像你给我的一样