curl - How to escape < in parameter value

十年热恋 提交于 2020-01-04 14:48:23

问题


Here is the curl command I'm executing

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

I'm trying to load openrdf repository. It gives me an error because there is a "<" character at in the value of "context" parameter. How to escape this "<" so curl does not think that I'm trying to load file content into "context" parameter

The error from curl is:

curl: (26) couldn't open file "http://example.com>"

I've tried to escape it with \ and using < and %3C but no luck because as soon as I try to do this then the other end is complaining that it did not get exactly http://example.com

This is what is sent from the browser form

------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--  

Any suggestions ?


回答1:


You can use curl's --form-string which is like -F but doesn't interpret leading @ and <:

   --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.


来源:https://stackoverflow.com/questions/25484313/curl-how-to-escape-in-parameter-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!