July 2017
Intermediate to advanced
656 pages
16h 1m
English
If the endpoint is encrypted (for example, a standard HTTPS endpoint), we simply swap out the http module for the https module; the rest of the code remains the same.
In the headers of the opts object, we set Content-Type and Content-Length headers. While the request will still be successful without providing Content-Length , it is good practice and allows the server to make informed assumptions about the payload. However, setting Content-Length to a number lower than the payload size will result in an error. This is why it's important to use Buffer.byteLength , because this gives the exact size of the string in bytes, which can differ from the string length when Unicode beyond the ASCII range are in the string (since Unicode ...