Editing
Troubleshooting of curl errors in Mandarin
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 如何解決 zsh Event Not Found 錯誤 === 在 zsh shell 中執行包含 JSON 資料的 cURL 命令時,你可能會遇到以下錯誤訊息: <pre> > zsh: event not found: \ </pre> 這是因為 zsh 將驚嘆號 (!) 解釋為歷史展開字元,即使它出現在雙引號內也是如此。 要解決此錯誤,可以使用以下任一方法: '''方法 1:對 JSON 資料使用單引號''' {{kbd | key=<nowiki>-d '{"message": "Hello '\''world'\'' & welcome!", "price": "$19.99"}'</nowiki>}} '''方法 2:跳脫驚嘆號''' {{kbd | key=<nowiki>-d "{\"message\": \"Hello 'world' & welcome\!\", \"price\": \"\$19.99\"}"</nowiki>}} '''方法 3:使用 heredoc 搭配 stdin''' {{kbd | key=<nowiki>-d @- << 'EOF'</nowiki>}} '''方法 4:將 JSON 儲存到檔案並引用''' {{kbd | key=<nowiki>-d @payload.json</nowiki>}} '''方法 5:暫時停用歷史展開功能'''<ref>[https://www.reddit.com/r/bash/comments/cl54to/not_sure_why_mac_is_saying_bash_event_not_found/?show=original not sure why mac is saying `-bash: !": event not found` when I try to simply echo a string containing a "!" : r/bash]</ref> {{kbd | key=<nowiki>set +H</nowiki>}} (在命令之前執行) 修正語法的範例: 使用單引號: <pre> curl -X POST \ -H "Content-Type: application/json" \ -d '{"message": "Hello '\''world'\'' & welcome!", "price": "$19.99"}' \ -v \ https://example.com/api/ </pre> 使用 heredoc(建議用於複雜的 JSON): <pre> curl -X POST \ -H "Content-Type: application/json" \ -d @- \ -v \ https://example.com/api/ << 'EOF' { "message": "Hello 'world' & welcome!", "price": "$19.99", "special_chars": "!@#$%^&*()_+{}|:<>?[]\\;'\",./" } EOF </pre> 使用外部 JSON 檔案: <pre> curl -X POST \ -H "Content-Type: application/json" \ -d @payload.json \ -v \ https://example.com/api/ </pre> 注意:建議使用 heredoc 方法來處理複雜的 JSON,因為它可以避免所有 shell 解釋問題並保持可讀的格式。
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information