Bug #75829 [Opn]: cURL and file_get_contents does not work with URL containing special character
| From: | marco dot marsala at live dot it | Date: | Wed, 17 Jan 2018 07:59:10 +0000 |
| Subject: | Bug #75829 [Opn]: cURL and file_get_contents does not work with URL containing special character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213576@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75829&edit=1
ID: 75829
User updated by: marco dot marsala at live dot it
Reported by: marco dot marsala at live dot it
-Summary: cURL and file_get_contents does not work with URL
contanining special character
+Summary: cURL and file_get_contents does not work with URL
containing special character
Status: Open
Type: Bug
Package: URL related
Operating System: both Ubuntu and Windows
PHP Version: 7.2.1
Block user comment: N
Private report: N
New Comment:
I don't think is a duplicate of #48550 but a much broader vision of the issue.
Previous Comments:
------------------------------------------------------------------------
[2018-01-17 07:52:57] marco dot marsala at live dot it
Description:
------------
cURL and file_get_contents does not work with URL contanining special characters (for example:
accented letters, quotes).
The URL sent to the remote server is badly encoded; special characters should be encoded as
urlencode() would, like any modern web browser does.
Test script:
---------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824");
echo curl_exec($ch); // got server error page
echo file_get_contents("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824");
// got server error page
// my function to fix encoding
function urlencode_parts($url) {
$parts = parse_url($url);
$parts['path'] = implode('/', array_map('urlencode',
explode('/', $parts['path'])));
$url = new \http\Url($parts);
return $url->toString();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, urlencode_parts("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824"));
echo curl_exec($ch); // now ok
echo file_get_contents(urlencode_parts("https://www.astegiudiziarie.it/vendita-asta-appartamento-genova-via-san-giovanni-d'acri-14-1360824"));
// now ok
Expected result:
----------------
The script should download the same page you can see with a web browser.
Actual result:
--------------
The server replies with a server error page.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75829&edit=1