56

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?

2
  • 2
    Is the server even receiving requests? It looks like you're URL encoding the whole URL... which would create an unusable URL. Commented Oct 4, 2012 at 20:38
  • Did you really try --data-urlenconded? Spelling this correctly might help you. Commented Feb 4, 2016 at 12:53

2 Answers 2

23

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hm, not sure if I understand correctly, what kind of error do you get? sed 's/\(..\)/%\1/g') is inside the $() evaluation, so escaping parenthesis is required. Without escaping them, sed will throw this error in sh, bash and zsh: \1 not defined in the RE.
comment deleted. I was only using the part of the command I needed and missed part of the context. disregard.
12

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.

1 Comment

Im on bash script. Do you have some example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.