DELETE using CURL with encoded URL

寵の児 提交于 2019-12-03 10:24:54

问题


I’m trying to make a request using CURL like this:

curl -X DELETE "https://myhost/context/path/users/OXYugGKg207g5uN/07V" 

where OXYugGKg207g5uN/07V is a hash, so I suppose that I need to encode before do this request.

I have tried curl -X DELETE --data-urlenconded "https://myhost/context/path/users/OXYugGKg207g5uN/07V"

Some ideas?


回答1:


If really OXYugGKg207g5uN/07V is the hash then you need to encode that, not the whole url. You can use an encoding function available inside the environment you use cURL in.




回答2:


Try this

curl -X DELETE "https://myhost/context/path/users/$(echo -ne "OXYugGKg207g5uN/07V" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g')"

It is equivilent to

curl -X DELETE "https://myhost/context/path/users/%4f%58%59%75%67%47%4b%67%32%30%37%67%35%75%4e%2f%30%37%56"

Here, every character is replaced by its byte respresentation... I don't think it is particularly pretty, but it works.



来源:https://stackoverflow.com/questions/12735450/delete-using-curl-with-encoded-url

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