Nit*_*kin 6 rest json powershell-5.0
我正在尝试使用powershell cmdlet Invoke-RestMethod
将json端点打印到控制台.
该命令成功执行,但最终结果是包含所有json的1级字段的终端表.
我正在运行这样的cmdlet:
Invoke-RestMethod -Uri <some url here> -Method GET -ContentType "application/json"
Run Code Online (Sandbox Code Playgroud)
得到这样的东西:
sections _links
-------- ------
{@{rel=parent; href=https://us9.api.mailchimp.com/3.0/templates/138...
Run Code Online (Sandbox Code Playgroud)
如何在不格式化的情况下将原始响应打印到终端?
首先,将-Method
和-ContentType
您所提供的默认值,你可以丢弃这些.为了得到json,把它扔回json.
Invoke-RestMethod -Uri "http://example.com/" | ConvertTo-Json -Depth 10
Run Code Online (Sandbox Code Playgroud)
我不知道你为什么要回到json,但好吧,你走了.
另一个答案适用于 JSON 响应,但 -UseBasicParsing 开关适用于任何响应类型:
(Invoke-WebRequest -UseBasicParsing -Uri 'http://example.com').Content
Run Code Online (Sandbox Code Playgroud)
只会给你响应内容(在 example.com 案例中,原始 html,或在你的用例中,原始 JSON)。
归档时间: |
|
查看次数: |
14497 次 |
最近记录: |