问题描述
当我使用curl库并尝试从url获取图像,我得到400错误的请求错误。
我发现,问题是与编码url。
但是在我的case它不工作,因为我的url - 它的路径到服务器端的图像像
http ://domain.com/images/products/product 1.jpg
我知道用户空间名称文件这是坏的做法,但它不是我的服务器,而不是我创建这些文件。
$ ch = curl_init
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_URL,urlencode($ url));
echo $ ret = curl_exec($ ch);
当我使用urlencode函数 - curl return http_code = 0
更新
$ url = str_replace('','+',$ url);
无法使用,伺服器传回404错误。
$ url ='http:// host / a b.img';
$ url = str_replace(,'%20',$ url);
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_URL,$ url);
echo $ ret = curl_exec($ ch);
when i use curl library and try to get image from url i get 400 bad request error.I founded that problem is with encoding url.But in my case it's not work, because my url - it's path to image on server side - like
http://domain.com/images/products/product 1.jpg
I understand that user spaces in name files it's bad practice, but it's not my server and not i created those files.
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, urlencode($url));
echo $ret = curl_exec($ch);
When i use urlencode function - curl return http_code = 0
Updated
$url = str_replace(' ', '+', $url);
doesn't work, server return 404 error.
Does this maybe work?
$url = 'http://host/a b.img';
$url = str_replace(" ", '%20', $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
echo $ret = curl_exec($ch);
这篇关于curl return 400 bad request(url with spaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!