To make an HTTP request with a custom body as HTML in TypeScript, you can use the Fetch API which is a modern replacement for the traditional XMLHttpRequest. The following code demonstrates how to make a HTTP POST request with a custom HTML body using Fetch API in TypeScript:
index.ts285 chars17 lines
In the above code, we define the url
and htmlBody
variables. We then make a fetch()
request with the POST
method and the htmlBody
passed as the body
property. We also set the Content-Type
header to text/html
. Finally, we handle the response or any errors that occur.
Note that the fetch()
API returns a Promise
so we can use then()
and catch()
to handle the response or any errors that occur.
gistlibby LogSnag