cURL requesting URL with whitespaces in URL.. What to do [duplicate]
Asked Answered
A

6

43

So I'm trying to curl this URL:

http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png

URL Encoded it reads as:

http%3A%2F%2Fimages.fastcompany.com%2Fupload%2FScreen+shot+2011-04-28+at+8.13.21+PM.png

However, curl needs it to be decoded into a proper URL obviously.

How do i get around this problem? cURL drops off the rest of the string as soon as it reaches any whitespace... :(

I should mention I can't wrap the URL with double quotes as it is a variable being posted.

Edit: hahahahaha wowwwwww brainfart.. thanks guys :P

Antiquity answered 9/5, 2011 at 2:16 Comment(1)
this is another alternative to doing exactly that: unix.stackexchange.com/questions/86729/…Alcina
H
47

Just use str_replace.

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );
Hectocotylus answered 9/5, 2011 at 2:23 Comment(0)
T
28

Perhaps try replacing spaces with %20?

Terrazzo answered 9/5, 2011 at 2:20 Comment(0)
L
10

I use:

$link = trim($link);
$link = str_replace ( ' ', '%20', $link);
Lathing answered 1/10, 2014 at 6:52 Comment(0)
T
3

For me just to put the name with spaces between "" worked.

Example

curl --upload-file "001- name - lastName.pdf" https://transfer.sh/ernesto

Notice the use of "" in "001- name - lastName.pdf"

Truncation answered 19/9, 2019 at 22:26 Comment(0)
X
2

Use the str_replace(); function. Replace your " " with "%20"

Xanthine answered 9/5, 2011 at 2:28 Comment(0)
S
0

On Windows, you can use notepad++

  1. Write the text in the file and open it in notepad++.
  2. Select an empty string in the text and then click on search.
  3. Search box will appear, Now click on replace tab.
  4. Select the Extended check box in the Search Mode option.
  5. Click replace enter image description here
Sizing answered 24/11, 2021 at 4:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.