[squeak-dev] Re: [ANN] WebClient and WebServer 1.0 for Squeak

Hannes Hirzel hannes.hirzel at gmail.com
Mon May 10 15:33:56 UTC 2010


Unfortunately UTF8TextConverter cannot deal with non-Latin1
characters. So it's usefulness is limited.

--Hannes

On 5/10/10, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
> Ok, the following works
>
> WebClient httpPut: host, '/notes/test11' content: '{"content":"',
> (UTF8TextConverter encodeByteString: 'äbc'), '"}' type: 'text/plain'.
>
> So I can manage.
>
> --Hannes
>
> On 5/10/10, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
>> The test case made simpler
>>
>> WebClient httpPut: host, '/notes/test7' content:
>> '{"content":"\uC3\uA4s"}' type: 'text/plain'.
>>
>> gives back as answer: '{"error":"bad_request","reason":"invalid UTF-8
>> JSON"}
>> '
>>
>> whereas
>>
>> WebClient httpPut: host, '/notes/test8' content: '{"content":"abc"}'
>> type: 'text/plain'.
>>
>> gives back
>> '{"ok":true,"id":"test8","rev":"1-f40e52919735ae6775af3d388361b3da"}
>> '
>>
>> --Hannes
>>
>> On 5/10/10, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
>>> Hello
>>>
>>> On 5/7/10, Andreas Raab <andreas.raab at gmx.de> wrote:
>>>> On 5/6/2010 3:32 PM, christophe.jalady at free.fr wrote:
>>>>> But it looks like there is a bug with the encoding !
>>>>
>>>> The behavior you are seeing is intentional. WebClient doesn't interpret
>>>> the content of a response. It simply gives you the bytes that you can
>>>> deal with in any way you see fit. That includes dealing with encodings.
>>>
>>>>> I have tried a quick test by replacing "ByteString" with "WideString"
>>>>> in
>>>>> WebResponse>>content without success.
>>>>
>>>> Yes, you need to decode the input. You can for example use the method
>>>> #utf8ToSqueak to decode the string into UTF-8.
>>>
>>>
>>> I have a similar problem, I want to post a document to a couchDB
>>> instance. Without German umlauts it works fine but if I add them I get
>>> an error message.
>>>
>>> host :='http://localhost:5984'.
>>> r := WriteStream on: (String new: 1000).
>>> d := Dictionary new. d at: 'content' put: 'äs' squeakToUtf8.
>>> (JsonObject newFrom: d) jsonWriteOn: r.
>>> WebClient httpPut: host, '/notes/test5' content:  r contents  type:
>>> 'text/plain;charset=utf-8'.
>>>
>>> The error message of the WebResponse is
>>> '{"error":"bad_request","reason":"invalid UTF-8 JSON"}
>>> '
>>>
>>> The same thing happens if I omit #squeakToUtf8
>>>
>>> If I inspect
>>>    r contents
>>> I get
>>>   '{"content":"\uC3\uA4s"}'
>>>
>>>
>>> Contrariwise if I post
>>>
>>>     host :='http://localhost:5984'.
>>>     r := WriteStream on: (String new: 1000).
>>>     d := Dictionary new. d at: 'content' put: 'abc' squeakToUtf8.
>>>     (JsonObject newFrom: d) jsonWriteOn: r.
>>>     WebClient httpPut: host, '/notes/test5' content:  r contents
>>> type: 'text/plain;charset=utf-8'.
>>>
>>> I get as answer
>>>     '{"ok":true,"id":"test5","rev":"1-f40e52919735ae6775af3d388361b3da"}
>>>     '
>>>
>>> How is this conversion supposed to be done?
>>>
>>> Hints and comments are appreciated.
>>>
>>> --Hannes
>>>
>>
>



More information about the Squeak-dev mailing list