I want to know the number of data bytes in a Json string sent by the server.

I’m trying to display the communication progress on the progress bar on the application side,
I would like to know the maximum number of bytes of data to be received.

The data retrieved from the server will be a Json format string.
I plan to display a progress bar with “UnityWebRequest.downloadedBytes” and the number of data bytes.

It’s not a file on the server, so I think there are some points that need to be calculated,
I think it would be easier if there was a function that could get the number of bytes.

Is there a function that can get the number of bytes on the Unity side?
Or is there a function to measure the number of bytes of transmitted data with lalavel?

I look forward to working with you.

Could you use UnityWebRequest.downloadProgress?

The server has to send a Content-Length header, otherwise there’s no way for Unity to know how much data it will send.

If the server does send the content length, then UnityWebRequest.downloadProgress will tell you the download progress. If you need to know the number of bytes, I think to only way is to subclass DownloadHandler and override DownloadHandler.ReceiveContentLengthHeader.

You need to check with your server framework for how to make sure a Content-Length header is sent. You might have to change how your data is generated/processed to make sure the size is known up-front and a Content-Length header can be sent.

1 Like