Sending 32k bytes from client to server with exe.json or similar?

Hello,

I’m using THttpServer.
Little question: What is the byte-size-limit for parameter param of exe.json?method=myMethod&param=...?

Context: I need to send ~ 32 000 bytes from client to server, if possible without webSockets.
From JavaScript, the client has to send something like:

const myObj = {"a": "b", "c": "d", "MANYOTHERFIELDS": "foo"}
const myStr = JSON.stringify(myObj);  // possibly 32 KB of data
const myUrl = "/myobject/myobject/exe.json?method=importData&param=" + myStr;

How to do this properly, such that importData can receive this 32k-byte string?

An alternative would be to do a POST request:

fetch("/myobject/myobject/exe.json?method=importData", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(myObj),
});

How is this possible inside THttpServer?

Thanks!

Maybe @linev can help

1 Like

Hi,

Some info about exe.json you can find in the documentation.

Suppose you have class ExeDispatcher with method importData(UserClass *arg);.
UserClass can be any class with members like “a” or “MANYOTHERFIELDS” and must have dictionary.

Then you can submit POST http request with argument arg=_post_object_json_. As post data ROOT JSON has to be supplied - see how TBufferJSON::ToJSON does this. In simple cases one just requires extra _typename field to let ROOT correctly parse your JSON.

Alternatively, you can define your method like: importData(const char *arg);. And then simply use base64 format to code arbitrary JSON string to value which can be submitted to the server as plain URL argument. Something like:

 fetch("/myobject/myobject/exe.json?method=importData&arg=" + btoa(JSON.stringify(myObj)), ...

In the method decode string with TBase64 class methods and then parse with any JSON parser.

Regards,
Sergey

Thank you @linev for your answer. In my case, the JSON to be sent from client to server is not at all linked to a user class / dictionary ; instead it is a fully custom JSON.
By the way it could be just “a string”.

How can the client send 32 KB of data to a function importData that runs on server?

I am afraid:

 fetch("/myobject/myobject/exe.json?method=importData&arg=" + btoa(myStr), ...

won’t work if myStr is ~ 32 KB.

Depending on the browser and on fetch implemenation, I think query string lenth is limited at around 2 KB or 8 KB.

How could we send such size of data to /myobject/myobject/exe.json?method=importData?

Thanks again if you have an idea.

You should try - probably limitation for 8000 symbols in URL string is no longer valid.
Question on stackoverflow is 16 years old.

But as I mention - you can try POST requests with properly formed JSON as post data.