英文:
How to send Post request in Github Actions under Windows?
问题
I need to notify Sentry about new build version when CI made it. I am using runs-on: windows-latest
for builds and sending requests with a code below:
- name: Notify Sentry
run: |
$VERSION_NAME = "${{ github.ref_name }}"
$REQUEST = "{\"version\": \"$VERSION_NAME\"}"
echo $REQUEST
curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"
Request looks correct, but it always returns error Expecting property name enclosed in double quotes
:
Run $VERSION_NAME = "${{ github.ref_name }}"
$VERSION_NAME = "${{ github.ref_name }}"
$REQUEST = "{\"version\": \"$VERSION_NAME\"}"
echo $REQUEST
curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"
shell: C:\Program Files\PowerShell\pwsh.EXE -command "'.\{0\}'"
{"version": "v1.1.1"}
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 104 100 87 100 17 313 61 --:--:-- --:--:-- --:--:-- 375
100 104 100 87 100 17 313 61 --:--:-- --:--:-- --:--:-- 375
{"error":"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"}
In Postman it works well. How to fix this error?
英文:
I need to notify Sentry about new build version when CI made it. I am using runs-on: windows-latest
for builds and sending requests with a code below:
- name: Notify Sentry
run: |
$VERSION_NAME = "${{ github.ref_name }}"
$REQUEST = "{`"version`": `"$VERSION_NAME`"}"
echo $REQUEST
curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"
Request looks correct, but it always returns error Expecting property name enclosed in double quotes
:
Run $VERSION_NAME = "${{ github.ref_name }}"
$VERSION_NAME = "${{ github.ref_name }}"
$REQUEST = "{`"version`": `"$VERSION_NAME`"}"
echo $REQUEST
curl -X POST -H "Content-Type:application/json" -d "$REQUEST" "https://sentry.io/api/hooks/release/builtin/...id.../...token.../"
shell: C:\Program Files\PowerShell\pwsh.EXE -command ". '{0}'"
{"version": "v1.1.1"}
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 104 100 87 100 17 313 61 --:--:-- --:--:-- --:--:-- 375
100 104 100 87 100 17 313 61 --:--:-- --:--:-- --:--:-- 375
{"error":"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"}
In Postman it works well. How to fix this error?
答案1
得分: 1
Use backslash instead of backtick to escape nested double quotes.
Change this:
$REQUEST = "{`"version`": `"$VERSION_NAME`"}"
to:
$REQUEST = "{\"version\": \"$VERSION_NAME\"}"
You may use single quotes instead of nested double ones and then use Replace
function to bulk escape those like this:
$REQUEST = "{'version': '$VERSION_NAME'}".Replace("'",'\"')
See: https://stackoverflow.com/questions/60819537
英文:
Use backslash instead of backtick to escape nested double quotes.
Change this:
$REQUEST = "{`"version`": `"$VERSION_NAME`"}"
to:
$REQUEST = "{\"version\": \"$VERSION_NAME\"}"
You may use single quotes instead of nested double ones and then use Replace
function to bulk escape those like this:
$REQUEST = "{'version': '$VERSION_NAME'}".Replace("'",'\"')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论