How to curl a URL with space in Windows?

1

I’m using Windows 10 and curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL.

I’m trying to download files from the ESA API using this curl command:

curl --ssl-no-revoke -u eduardojsilvajr \
    https://scihub.copernicus.eu/dhus/search?q=footprint:"Intersects(POLYGON((-4.53 29.85,26.75 29.85,26.75 46.80,-4.53 46.80,-4.53 29.85)))"

This is an example from the Copernicus Open Access Hub API site.

But when I run the above curl command, I get this message:

<?xml version="1.0" encoding="utf-8"?><feed xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom">
<title>Sentinels Scientific Data Hub search results for: footprint:Intersects(POLYGON((-4.53</title>
<subtitle>Displaying  results. Request done in 0.001 seconds.</subtitle>
<updated>2019-02-20T23:17:34.037Z</updated>
<author>
<name>Sentinels Scientific Data Hub</name>
</author>
<id>https://scihub.copernicus.eu/dhus/search?q=footprint:Intersects(POLYGON((-4.53</id>
<opensearch:totalResults/>
<opensearch:startIndex>0</opensearch:startIndex>
<opensearch:itemsPerPage>10</opensearch:itemsPerPage>
<opensearch:Query role="request" searchTerms="footprint:Intersects(POLYGON((-4.53" startPage="1"/>
<link rel="self" type="application/atom+xml" href="https://scihub.copernicus.eu/dhus/search?q=footprint:Intersects(POLYGON((-4.53&amp;start=0&amp;rows=10"/>
<link rel="first" type="application/atom+xml" href="https://scihub.copernicus.eu/dhus/search?q=footprint:Intersects(POLYGON((-4.53&amp;start=0&amp;rows=10"/>

As you can see there is a problem with spaces. I tried backslash, single quotes, double quotes, and passing the URL using a file (@file), but nothing makes this curl command work.

How do I make it work?

Eduardo Silva

Posted 2019-02-20T23:26:48.893

Reputation: 11

Try wrapping the whole URL in quotes like this: "https://scihub.copernicus.eu/dhus/search?q=footprint:Intersects(POLYGON((-4.53 29.85,26.75 29.85,26.75 46.80,-4.53 46.80,-4.53 29.85)))" – JakeGould – 2019-02-21T00:04:08.893

@JakeGould you haven't only wrapped his URL in quotes, you (rightly or wrongly), removed the quote he put before Intsersects and pretty much any other quotes he had within the URL (which may be correct - lets see, but you what you said you didn't adequately express what you actually did) – barlop – 2019-02-21T00:28:24.340

(1) Try using quotes and backslashes: "Intersects(POLYGON((-4.53\ 29.85,26.75\ 29.85,….  Try this with " and again with '. (2) The ugly answer: try replacing the spaces with %20; e.g., "Intersects(POLYGON((-4.53%2029.85,26.75%2029.85.….  Try this with and without quotes (but it’s probably best to use quotes). – Scott – 2019-02-21T00:33:21.233

@JakeGould i've already did this... didn't work – Eduardo Silva – 2019-02-21T03:26:48.800

@Scott after using \ before all spaces i can see using the -v parameters that de url was passed correctly but i'm still geting a "400 bad request" from the server. but i could manage to make thinks working using wget and ubuntu 16. thanks for the help – Eduardo Silva – 2019-02-21T03:34:11.463

Please post an answer describing how you solved the problem. – Scott – 2019-02-21T03:36:58.083

URL-encoding the URL first might work. – jamesdlin – 2019-02-21T03:44:59.403

@Scott using Linux and Wget we don't have problems to use " and '... so just put the url inside single quotes and i could use double quotes and spaces without any problems. – Eduardo Silva – 2019-02-22T05:19:33.463

Answers

0

You can use curl's built-in --data-urlencode switch like this:

curl --ssl-no-revoke -u eduardojsilvajr --data-urlencode "q=footprint:\"Intersects(POLYGON((-4.53 29.85,26.75 29.85,26.75 46.80,-4.53 46.80,-4.53 29.85)))\"" https://scihub.copernicus.eu/dhus/search

See the man page for more info.

Edrean Ernst

Posted 2019-02-20T23:26:48.893

Reputation: 1

Ha!  This question is four months old.  We have questions here that are over a decade old! – Scott – 2019-06-25T17:37:54.907