DELETE using CURL with encoded URL

后端 未结 2 679
忘了有多久
忘了有多久 2021-02-04 23:38

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

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

where OXYugG

2条回答
  •  礼貌的吻别
    2021-02-05 00:04

    Since you are in a bash environment, you could encode the hash OXYugGKg207g5uN/07V before passing it to curl.

    A straight-forward approach would be to use its byte representation %4f%58%59%75%67%47%4b%67%32%30%37%67%35%75%4e%2f%30%37%56

    To get that, call:

    echo -ne "OXYugGKg207g5uN/07V" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g'
    

    It will give you: %4f%58%59%75%67%47%4b%67%32%30%37%67%35%75%4e%2f%30%37%56

    The complete one-liner including curl in bash/zsh/sh/… would look like this:

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

    and is equivalent 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"
    

    This solution is not very pretty, but it works.
    I hope you find this helpful.

提交回复
热议问题