why is ZnEasy choking on this and languages as c# and ruby not

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

why is ZnEasy choking on this and languages as c# and ruby not

Pharo Smalltalk Users mailing list
Hello,

In a project of mine I do this : 

(ZnEasy get: 'https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak') contents .

but this is given me a bytearray.

When I do the same in other languages I know like c# or ruby I get a dictionary like I suspect. 


Can som one explain to me why this happens with ZnEasy. 

Regards, 

Roelof

Reply | Threaded
Open this post in threaded view
|

Re: why is ZnEasy choking on this and languages as c# and ruby not

Sven Van Caekenberghe-2


> On 27 Sep 2020, at 19:34, Roelof Wobben via Pharo-users <[hidden email]> wrote:
>
> Hello,
>
> In a project of mine I do this :  
>
> (ZnEasy get: 'https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak'
> ) contents .
>
> but this is given me a bytearray.
>
> When I do the same in other languages I know like c# or ruby I get a dictionary like I suspect.
>
>
> Can som one explain to me why this happens with ZnEasy.
>
> Regards,
>
> Roelof

This website/webservice has an incomplete http 1.1 fallback IMHO, as it does not set the content-type of the response - in that case the default is application/octet-stream, hence a ByteArray.

You can see this when you ask curl to use http 1.1

$ curl -v --http1.1 https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak

You will see there is no content-type in the response. Now, curl too will seemingly show you the expected text, but that is an assumption it cannot actually make (it does this in a unix tradition).


Now, since we know/expect textual JSON data (apparently), you can make the request work as follows:

(ZnEasy get: 'https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak') contents utf8Decoded.

When you have NeoJSON load, you can parse as follows:

NeoJSONObject fromString: (ZnEasy get: 'https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak') contents utf8Decoded.


Sven
Reply | Threaded
Open this post in threaded view
|

Re: why is ZnEasy choking on this and languages as c# and ruby not

Esteban A. Maringolo
In reply to this post by Pharo Smalltalk Users mailing list
Hi Roelof,

As pointed in the Discord chat, and just for others to know, the HTTP
response is not correct since it doesn't set any MIME Type, so Zinc
(ZnEasy) does the correct thing that it is to assume the content is
application/octet-stream, so you get a ByteArray. If you decode such
bytearray using UTF8 you'll get the "text" you're expecting.

Just out of curiosity, can you show us a snippet of how you do that in
C# and Ruby?

Regards,

Esteban A. Maringolo

On Sun, Sep 27, 2020 at 2:35 PM Roelof Wobben via Pharo-users
<[hidden email]> wrote:

>
> Hello,
>
> In a project of mine I do this :
>
> (ZnEasy get: 'https://www.rijksmuseum.nl/api/nl/collection/SK-C-1368/tiles?key=14OGzuak') contents .
>
> but this is given me a bytearray.
>
> When I do the same in other languages I know like c# or ruby I get a dictionary like I suspect.
>
>
> Can som one explain to me why this happens with ZnEasy.
>
> Regards,
>
> Roelof
>