-1

I have an api server that support the urls to be in this format

api.add_resource(Component, '/mycustom-url/<string:text>',
             methods=['GET'])

I need to support using it with curl.

The string might be arabic, so we need to urlencode before sending with curl. I want to do it through the curl command directly.

In docs, I can see using -d with query string

curl -d "name=curl" https://example.com

Is there a way to use it for full urlencode or the last parameter part?

eg: I want to be able to call curl https://example.com/mycustom-url/عربي. without url encoding then send the long encoded one through curl?

palAlaa
  • 9,500
  • 33
  • 107
  • 166
  • see: https://stackoverflow.com/a/2027690/724039. `curl -G --data-urlencode "name=curl" https://example.com` – Luuk Sep 12 '21 at 08:29

2 Answers2

0

Suppose you have the following PHP script (named: test.php):

<?php
echo "GET:";
var_dump($_GET);

Then this:

curl -G --data-urlencode "name=%E2%82%AC" http://localhost/test.php?name2=%E2%82%AC

Will produce:

GET:array(2) {
  ["name2"]=>
  string(3) "€"
  ["name"]=>
  string(9) "%E2%82%AC"
}
  • You see that the name is not urldecoded, and that name2 is urldecoded.
  • The characters %E2%82%AC represent the urlencoded character

Conclusion: you still need the to urlencode the string...

Luuk
  • 12,245
  • 5
  • 22
  • 33
  • That's what the docs provides, I can't use querystring, the api is there n can't change it, I need to work with it as is, and it's format is /url/param. No querystring. U got the need? – palAlaa Sep 12 '21 at 10:51
0

I find the solution for this issue is to put the arabic string inside "" and add space to the url

eg.

curl  https://example.com/mycustom-url/" عربي"

This way the bash will interpret the string as part of the url and concatenate the string to the url. It will be sent implicitly with url encoding and the api will receive it successfuly.

palAlaa
  • 9,500
  • 33
  • 107
  • 166