asHttp with chunked

Is there someone, who have experience with http and chunked encoding? I need to communicate with Teltonika routers and I don’t know, how to turn off the chunked :exploding_head:

@NovotnyJ,
I’ve no experience with chunked encoding, and I’m not even sure if AsHttp supports it… but I’m interested in the use-case, as I’m also using a small Teltonika device (RUT241) inside a private project.
Which Teltonika router do you use, and what service of the router do you want to query?

@alexander.hefner

I have RUT260, but in future I plan use RUTM11,…

I need to send SMS. I have functionally legacy princip (cgi-bin), but it’s not supported in newer firmware (about 7.14 they remove it), so I don’t want to risk to use this (now is 7.22). So I am now using their REST API (https://developers.teltonika-networks.com/). It’s little bit complicated, because token logins, but nothing impossible I think. And when I am sending request, it’s respond (in router I see success login) with 200 OK, the HTTP1.1 always, but response is empty and status return 35566. I try to find some solution (over postman it’s OK) and after searching with AI, I found, that it’s chunked. Chunked means, that the message is sending in more messages without defined content-lenght.

I have already fully functionally receiving SMS over httpsService and there is no problem.

@NovotnyJ ,

okay, understood, thanks for the details!

After having a bit deeper look into the chunked encoding (Deep Dive - How Chunked Transfer Encoding Works - Sahan Serasinghe - Engineering Blog), I’m pretty sure the AsHttp library does not support it, unfortunately.

The error status 35566 additionally points into that direction: as the chunks aren’t sent with a HTTP header at all but just as a hex-coded chunk length followed by the chunk content, I think that’s the reason why AsHttp throws an “illegal character” error (because if the AsHttp functions doesn’t decode and handle “Transfer-Encoding: chunked” header line in the first and only HTTP header sent when beginning a chunked transfer, the next message sent by the server starts with that “illegal character” = hex-coded chunk length).

Based on that guess, I recommend at least to contact your local B&R support, if they can create a case for a future implementation of chunked encoding support in AsHttp.

As additional information:
in past, I struggeled with some other topic in AsHttp (SSL was not available in AsHttp when I needed it → so this example is quite old).
It’s not comparable to your topic, but nevertheless maybe it’s worth thinking about if that could solve it?

In my case, I …

  • … just used the AsHttp functions for building some some formatting (= the Encoding functions of AsHttp + HttpSetParamUrl)
  • … built then the HTTP header + content for the needed POST request via string functions (as HTTP header format itself is more or less just “<Header_url>\r\n” plus a series of “<field_name>: <field_value>\r\n” followed by “\r\n\n <…content…>”)
  • … and used native AsTcp() for Open,Send,Receive,Close in direction of the web server

He’re just some excerpts from the program I used years ago (please ignore some strange commands/comments :wink: ) :

Defining my own header strings:

Using AsHttp as helper functions:


Copying all into send buffer:

Sending + Receiving via AsTcp (Open, Close, parsing received data a.s.o. not included in the screenshot):

Best regards!

1 Like

The AsHttp Library does not support chunk. You could try out our (Loupe) http client, I think we added chunked, although it’s possible it’s in a branch.

Docs: Usage :: Loupe Documentation

Source:

4 Likes

I try Loupe library from @Josh_Polansky , but I was not able to build the library in AS6. My incompetence, because Josh managed it.

From the official support, it doesn’t look like they will be addressing this anytime soon.

So I write my own HTTPclient. It’s now little messy with no docs, but functionally with teltonika.