'Postman and content-length

From my laptop I initiated a POST request to my web server. The HTTP POST request looks something like this (when seen via POSTMAN console)

POST /api/fwupgrade HTTP/1.1
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 2b1e72fa-f43b-4fc9-9058-e78533c30f0f
Host: 192.168.71.24
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------572971355726244237076370
Content-Length: 222
----------------------------572971355726244237076370
Content-Disposition: form-data; name="FileName"; filename="help.txt"

<help.txt>

The content-length is indicated as 222. the file help.txt has the following characters only (for test I put 10 a) aaaaaaaaaa

When I receive a http request on the server, I parse the request and I see the content-length as 222. Now my questions:

a) I assume this content length 222 includes the bytes after the line "Content-Length: 222" am I right? So this would mean the request body starts from

 ------------------572971355726244237076370
    Content-Disposition: form-data; name="FileName"; filename="help.txt"

    <help.txt>

Is this understanding correct?

b) Does the request body always follow the same format i.e after "Content-Length:" it begins and ends with the data of the file, in my case "help.txt"?

c) Assuming #a is correct, I calculate the actual data to be starting from the location after filename="help.txt" /r/n and then store this in a file on my server. However I get 58 surplus bytes after the aaaaaaaaaa. Any idea how am I supposed to interpret Content-length or how postman calculates the Content-length field?

Regards



Solution 1:[1]

a) Roughly yes. b) It depends on the Content-Type (here: multipart/form-data) c) You'll need a parser for multipart/form-data messages. See, for instance, https://greenbytes.de/tech/webdav/rfc7578.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Julian Reschke