To make an HTTP request with a custom body as HTML in Ruby, you can use the net/http
library. Here's an example code snippet that creates a POST request with a custom HTML body and sends it to a specified URL:
main.rb318 chars14 lines
In this example, we first create a URI
object representing the URL we want to send the request to. We then create a new Net::HTTP::Post
object and set its Content-Type
header to 'text/html'
, indicating that the body of the request is HTML.
We then set the body of the request to the custom HTML code using the body
method. Finally, we use the start
method of Net::HTTP
to send the request and receive the response, which we print to the console with puts
.
Note that you may need to replace example.com
, /path/to/resource
, and the custom HTML body in this code with your own values, depending on the specific URL you're working with and the HTML you want to send.
gistlibby LogSnag