我需要一个简单的字符串发送到使用PowerShell网络API,我必须确保在HTML体值有"行情",围绕它,因为它的内容类型必须是application/JSON.
例如:
$specialKey = "101010"
Invoke-RestMethod -Method Put `
-Uri $keyAssignmentUri `
-Header @{"content-type"="application/json"} `
-Body "$specialKey"
Run Code Online (Sandbox Code Playgroud)
当我在Fiddler中检查这个电话时,我发现身体是101010而不是"101010".如何使用引号发送正文值?
小智 7
为了获得“报价”,您需要在每个要打印或发送的“”之前提供转义字符(`)。
$PrintQuotesAsString = "`"How do I escape `"Quotes`" in a powershell string?`""
Write-Host $PrintQuotesAsString
"How do I escape "Quotes" in a powershell string?"
Run Code Online (Sandbox Code Playgroud)
用一系列反斜杠、反引号和双引号替换双引号 (") 对我有用:
\`"
Run Code Online (Sandbox Code Playgroud)
示例:我想(使用env命令)将名为SCOPES的环境变量设置为以下值,然后启动node app.js:
{
"email":"Grant permissions to read your email address",
"address":"Grant permissions to read your address information",
"phone":"Grant permissions to read your mobile phone number"
}
Run Code Online (Sandbox Code Playgroud)
所以我用:
env SCOPES="{ \`"email\`": \`"Grant permissions to read your email address\`", \`"address\`": \`"Grant permissions to read your address information\`", \`"phone\`": \`"Grant permissions to read your mobile phone number\`" }" node app.js
Run Code Online (Sandbox Code Playgroud)
参考资料:http : //www.rlmueller.net/PowerShellEscape.htm
| 归档时间: |
|
| 查看次数: |
6454 次 |
| 最近记录: |