thanasissdr
thanasissdr

Reputation: 817

Use curl with a string input parameter in the url

I want to use curl for a GET request, but the url is of the form:

localhost:<port>/getter?key=This is a sentence., which means that the key is an input parameter in the endpoint.

If I use POSTMAN for the request, then the format with the spaces is absolutely fine.

I have a hard time giving the right format when I use curl. I have tried using the percentage symbol when we have spaces, but I cannot figure it out.

Upvotes: 0

Views: 771

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185700

Replace:

localhost:<port>/getter?key=This is a sentence

by

'http://localhost:<port>/getter?key=This%20is%20a%20sentence'

Note the %20.

If you want a command line to do it for you :

echo "/getter?key=This is a sentence" |
    perl -MURI::Escape -lne 'print uri_escape($_);'

Upvotes: 1

Related Questions