Powershell从文件调用Rest方法方法主体

问题描述

我是Powershell的初学者,他正尝试通过单独文件发送带有正文的POST请求。

我正在尝试使用 -infile ,但它不起作用?

以下是我要运行的示例:

$response = Invoke-RestMethod -InFile $test_rd.txt '*https://www.EXAMPLE_URL.com*' -Method 'POST'
$response | ConvertTo-Json

这是Body文件中的内容

$body = "<List Name="test_rd" Action="Update">
`n  <Columns>
`n    <c>FA No.</c>
`n    <c>Location</c>
`n    <c>Location Name</c>
`n    <c>Line of Business</c>
`n    <c>Line of Business Name</c>
`n    <c>Area/CMU/Paypoint</c>
`n    <c>Model Code</c>
`n  </Columns>
`n  <Rows>
`n    <r>
`n      <v>6930</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall/Oscar</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6931</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>3</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6932</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>1</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6945</v>
`n      <v>151990</v>
`n      <v>Southcenter WA</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6989</v>
`n      <v>151838</v>
`n      <v>Meriden CT</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n  </Rows>
`n</List>"

这是我得到的答复? [ [

    ],[

    ],[
        [

        ],[
            "System.Xml.XmlWhitespace","System.Xml.XmlElement","System.Xml.XmlWhitespace","System.Xml.XmlWhitespace"
        ],[

        ]
    ]
]

应该得到这个吗?

[
    [

    ],[
        [

        ]
    ]
]

这是该帖子的示例,没有单独的文件 -infile

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type","application/xml")

$body = "<List Name=`"test_rd`" Action=`"Update`">
`n  <Columns>
`n    <c>FA No.</c>
`n    <c>Location</c>
`n    <c>Location Name</c>
`n    <c>Line of Business</c>
`n    <c>Line of Business Name</c>
`n    <c>Area/CMU/Paypoint</c>
`n    <c>Model Code</c>
`n  </Columns>
`n  <Rows>
`n    <r>
`n      <v>6930</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall MALL</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6931</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>3</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6932</v>
`n      <v>151128</v>
`n      <v>Viewmont Mall</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>1</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6945</v>
`n      <v>151990</v>
`n      <v>Southcenter WA</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n    <r>
`n      <v>6989</v>
`n      <v>151838</v>
`n      <v>Meriden CT</v>
`n      <v>2100</v>
`n      <v>Strollers</v>
`n      <v>2</v>
`n      <v>CMU3+</v>
`n    </r>
`n  </Rows>
`n</List>"

$response = Invoke-RestMethod *'https://www.EXAMPLE_URL.com'* -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...