cURL requesting URL with whitespaces in URL.. What to do

爱⌒轻易说出口 提交于 2019-12-06 16:44:37

问题


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


回答1:


Just use str_replace.

echo str_replace ( ' ', '%20', 'http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png' );



回答2:


Perhaps try replacing spaces with %20?




回答3:


I use:

$link = trim($link);
$link = str_replace ( ' ', '%20', $link);



回答4:


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




回答5:


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"



来源:https://stackoverflow.com/questions/5931853/curl-requesting-url-with-whitespaces-in-url-what-to-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!