[Pharo-project] Fwd: [Moose-dev] ZnUrl, Encoding
I assume this question is better placed here .... I am interested in the answer as well. --Hannes ---------- Forwarded message ---------- From: Dennis Schenk <d.schenk@students.unibe.ch> Date: Tue, 22 Jan 2013 14:00:06 +0100 Subject: [Moose-dev] ZnUrl, Encoding To: Moose-related development <moose-dev@iam.unibe.ch> Hi all, I stumpled upon a problem with encoding of URLs in Pharo. I am using the Google Geocoding API. For example I want to get the result of: http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en When one enters this in a Browser a correct JSON response is returned. If I do the following: *(Url absoluteFromText: ' http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en<http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Cura%C3%A7ao&sensor=false&language=en>') retrieveContents contents.* I get an error back grom Google. When digging through the code I found that in ZnHTTPSocketFacade the following happens: *' http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en<http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Cura%C3%A7ao&sensor=false&language=en>' asZnUrl * And the result of this is: http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Cura%C3... * * Which Google does not know how to handle and then returns an error. Does anyone have an idea how I could get contents from a URL which has special chars like '*ç'?* Or is there a way to convert all special chars to to their 'normal' counterparts, like *ç -> c?* * * Cheers, Dennis
Hi Dennis, I don't know where you were trying this, it does not change the explanation, but in Pharo 2.0 with the latest Zinc HTTP Components code, your example gives an error: 'http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en' asZnUrl retrieveContents. ZnCharacterEncodingError: ASCII character expected. and rightfully so: an encoded URL cannot contain these characters. There is a difference between internal and external encoding of URLs and of ZnUrl. One way to do it correctly is: 'http://maps.googleapis.com/maps/api/geocode/json' asZnUrl queryAt: #address put: 'Willemstad, Curaçao'; queryAt: #sensor put: 'false'; queryAt: #language put: #en; retrieveContents. Please check the extensive class comment of ZnUrl. Leave the problem of encoding to ZnUrl, supply the internal values directly ;-) So why does it work in your browser ? Because your browser's URL entry field has very permissive parsing, doing this conversion as an extra service, above what is required. ZnUrl is stricter. HTH, Sven On 22 Jan 2013, at 15:13, "H. Hirzel" <hannes.hirzel@gmail.com> wrote:
I assume this question is better placed here ....
I am interested in the answer as well.
--Hannes
---------- Forwarded message ---------- From: Dennis Schenk <d.schenk@students.unibe.ch> Date: Tue, 22 Jan 2013 14:00:06 +0100 Subject: [Moose-dev] ZnUrl, Encoding To: Moose-related development <moose-dev@iam.unibe.ch>
Hi all,
I stumpled upon a problem with encoding of URLs in Pharo.
I am using the Google Geocoding API. For example I want to get the result of: http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en
When one enters this in a Browser a correct JSON response is returned.
If I do the following:
*(Url absoluteFromText: ' http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Curaçao&sensor=false&language=en<http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Cura%C3%A7ao&sensor=false&language=en>') retrieveContents contents.*
I get an error back grom Google.
When digging through the code I found that in ZnHTTPSocketFacade the following happens:
And the result of this is:
http://maps.googleapis.com/maps/api/geocode/json?address=Willemstad,+Cura%C3... * * Which Google does not know how to handle and then returns an error.
Does anyone have an idea how I could get contents from a URL which has special chars like '*ç'?*
Or is there a way to convert all special chars to to their 'normal' counterparts, like *ç -> c?* * * Cheers, Dennis
-- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
participants (2)
-
H. Hirzel -
Sven Van Caekenberghe