php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48550 cURL does not work when the URL has a ’ character in it.
Submitted: 2009-06-14 17:13 UTC Modified: 2009-06-15 17:51 UTC
From: victorepand at gmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.9 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: victorepand at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-14 17:13 UTC] victorepand at gmail dot com
Description:
------------
cURL does not work when the URL has a ’ character in it. Such as, for example, this one:

http://www.motorcycle-superstore.com/ProductImages/60/2009_GMax_Women’s_GM17_Derk_Open-Face_Helmet.jpg

Reproduce code:
---------------
$ch=curl_init();
$url="http://www.motorcycle-superstore.com/ProductImages/60/2009_GMax_Women’s_GM17_Derk_Open-Face_Helmet.jpg"
curl_setopt($ch,CURLOPT_URL,$url);
$result=curl_exec ($ch);

Expected result:
----------------
thumbnail image in binary stored in result

Actual result:
--------------
curl error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-15 14:31 UTC] jani@php.net
What error does it give? See http://www.php.net/curl_error
 [2009-06-15 15:50 UTC] victorepand at gmail dot com
The error returned by cURL is:
22 The requested URL returned error: 404

I created this function which solves the problem:

function urlencode_url($url) {
   if (!($ei=strpos($url,"?"))) $ei=strlen($url);
   $newurl=str_replace(array("%3A","%2F"),array(":","/"),urlencode(urldecode(substr($url,0,$ei)))).substr($url,$ei);
   return $newurl;
}

By passing the URL through this function, the offending character is converted to its urlencoded equivalent (%##). With these codes instead of the bad character, cURL reads the URL with no problem.

Nonetheless, I reported this issue because Internet Explorer does not require the urlencoded codes. It loads the original URL with no problem, using the original bad character in the URL. Therefore, the cURL behavior is more strict in its requirement of the URL being urlencoded than Internet Explorer is.

Perhaps cURL could automatically urlencode the URL, or perhaps a function should be made for this purpose like the one I have shown above.
 [2009-06-15 17:51 UTC] jani@php.net
Well, browsers do a lot of thing automatically you need to do yourself 
when you do it yourself. This is obviously not any bug. (tested with 
curl on command line with same result..)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC