2017-06-30 5 views
1

Powershellを使用してWebアプリケーションに簡単な文字列を送信する必要があります。コンテンツタイプがapplication/jsonでなければならないため、HTML本文の値に「引用符」が付いていることを確認する必要があります。例えばPowerShellの文字列で "Quotes"をエスケープするにはどうすればよいですか?

:私はフィドラーでこのコールを検査する場合

$specialKey = "101010" 
Invoke-RestMethod -Method Put ` 
       -Uri $keyAssignmentUri ` 
       -Header @{"content-type"="application/json"} ` 
       -Body "$specialKey" 

は、私は体が101010の代わりに「101010」であることがわかります。どのように引用符で本文の値を送信しますか?

+0

'-body($ specialKey |をConvertTo-JSON)。?' – wOxxOm

+0

便利な[引用符のブログ](https://blogs.technet.microsoft.com/heyscriptingguy/ 2015/06/20/weekend-scripter-understanding-quoters-marks-in-powershell /) –

答えて

4

それ文字列リテラルにするために、単一引用符で囲み:「引用」を持つために

$specialKey = '"101010"' 
1

、あなたは「すべての前にエスケープ文字( `)を提供する必要がありますが、印刷したいですまたは送信

$PrintQuotesAsString = "`"How do I escape `"Quotes`" in a powershell string?`"" 

Write-Host $PrintQuotesAsString 

"How do I escape "Quotes" in a powershell string?" 

enter image description here

関連する問題