pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

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

RW
Roelof Wobben
Sun, Sep 27, 2020 5:34 PM
SV
Sven Van Caekenberghe
Sun, Sep 27, 2020 8:37 PM

On 27 Sep 2020, at 19:34, Roelof Wobben via Pharo-users pharo-users@lists.pharo.org 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

> On 27 Sep 2020, at 19:34, Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org> 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
EM
Esteban Maringolo
Sun, Sep 27, 2020 11:11 PM

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 pharo-users@lists.pharo.org 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

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 <pharo-users@lists.pharo.org> 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 >