curl - 如何在参数值中转义 <

szy*_*dan 2 curl escaping

这是我正在执行的 curl 命令

curl -F "context=<http://example.com>" \
     -F "Content-Type=text/plain" \
     -F "source=file" \
     -F "content=@members.nt;type=text/plain" \
     http://localhost:8080/openrdf-workbench/repositories/XXX/add
Run Code Online (Sandbox Code Playgroud)

我正在尝试加载 openrdf 存储库。它给了我一个错误,因为“上下文”参数的值中有一个“<”字符。如何转义这个“<”,所以 curl 不认为我正在尝试将文件内容加载到“context”参数中

curl 的错误是:

curl: (26) couldn't open file "http://example.com>"
Run Code Online (Sandbox Code Playgroud)

我试图用 \ 并使用 < 和 %3C 来逃避它,但没有运气,因为一旦我尝试这样做,另一端就会抱怨它没有得到完全 http://example.com

这是从浏览器表单发送的内容

------WebKitFormBoundaryl8CUSIvy5962lwBF
Content-Disposition: form-data; name="baseURI"


------WebKitFormBoundaryl8CUSIvy5962lwBF
Content-Disposition: form-data; name="context"

<http://example.com>
------WebKitFormBoundaryl8CUSIvy5962lwBF
Content-Disposition: form-data; name="Content-Type"

text/plain
------WebKitFormBoundaryl8CUSIvy5962lwBF
Content-Disposition: form-data; name="source"

file
------WebKitFormBoundaryl8CUSIvy5962lwBF
Content-Disposition: form-data; name="content"; filename="members.nt"
Content-Type: application/octet-stream


------WebKitFormBoundaryl8CUSIvy5962lwBF--  
Run Code Online (Sandbox Code Playgroud)

有什么建议 ?

Jak*_*ski 5

您可以使用 curl's --form-string,它类似于-F但不解释前导@<

   --form-string <name=string>
          (HTTP)  Similar  to --form except that the value string for the named parameter is used literally. Leading '@' and '<' characters, and the ';type=' string in the value have
          no special meaning. Use this in preference to --form if there's any possibility that the string value may accidentally trigger the '@' or '<' features of --form.
Run Code Online (Sandbox Code Playgroud)