Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 640 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I escape "Quotes" in a powershell string?

#1
I need to send a simple string to a web api using Powershell, and I have to ensure the value in the HTML body has "Quotes" around it, because the content type has to be application/json.

For example:

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

When I inspect this call in Fiddler, I see that the body is 101010 instead of "101010". How do I send the body value with quotes?
Reply

#2
In order to have the "Quotes", you need to provide the escape character (`) before every " which you want to print or send.

$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][1]][1]


[1]:
Reply

#3
Replacing double quotes (") with a sequence of back-slash, backtick and double-quotes worked for me:

\`"

**Example**: I want to set (using the *env* command) an environment variable named *SCOPES* to the following value, then launch *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"
}

so I used:

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

References:

[To see links please register here]

Reply

#4
Assuming you don't need to do variable substitution in your string, a simple solution is to just surround it with single quotes to make it a literal string:

$specialKey = '"101010"'
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through