如何逃脱重定向(<<) character in a JSON string contained in a cURL command?

问题描述 投票:0回答:1

我有一个 HTTP CRUD API,我能够成功向其发送命令。我在 Windows 11 上的命令提示符下使用 cURL。

但是,当我发送重定向字符时,“<<", as part of a JSON string, I get an error.

cURL 命令示例:

curl -X "PUT" -H "Content-Type: application/json" -d "{\"id\": \"b6481929-ec66\", \"dialogue\": \"<b> <<winks>>You are kewl </b>\"}" https://myfakeurl.xyz/items

错误:

<< was unexpected at this time.

有谁知道我如何成功转义重定向字符(<<) in my JSON string within the cURL command?

我尝试按照中引用的方式使用 Windows 转义字符 ^ 在 Windows 命令提示符中转义尖括号

更新:

使用 ^ 字符,这里是我输入的 cURL 命令的修改 JSON 部分:

 "{\"id\": \"b6481929-ec66\", \"dialogue\": \"^<^ b> ^<^<winks^>^> You are kewl ^<^/b>\"}"

我收到的错误:

文件名、目录名或卷标语法不正确。

我还尝试了以下变体 << portion of the JSON string:

^<^<^winks^>^>

^<^^<^winks^>^>

我运行的是 Windows 11 专业版。构建版本是10.0.22631.3737。

json curl
1个回答
0
投票

这是一个微不足道的答案,我同意在适当的情况下删除(例如,因拼写错误而关闭)

c:\temp>curl -X "PUT" -H "Content-Type: application/json" -d "{\"id\": \"b6481929-ec66\", \"dialogue\": \"^<b^> ^<^<winks^>^>You are kewl ^</b^>\"}" https://httpbin.org/anything/anything
{
  "args": {},
  "data": "{\"id\": \"b6481929-ec66\", \"dialogue\": \"<b> <<winks>>You are kewl </b>\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Content-Length": "69",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.7.1",
    "X-Amzn-Trace-Id": "Root=1-6684ef46-37d0b89965dd85fa60a3bed9"
  },
  "json": {
    "dialogue": "<b> <<winks>>You are kewl </b>",
    "id": "b6481929-ec66"
  },
  "method": "PUT",
  "origin": "REDACTED",
  "url": "https://httpbin.org/anything/anything"
}

c:\temp>
© www.soinside.com 2019 - 2024. All rights reserved.