To make an HTTP request with a custom body as text in Ruby, we can use the Net::HTTP
library. Here's an example:
main.rb190 chars9 lines
In this example, we're making a POST
request to http://example.com/api
with the body of the request set to 'This is the body of the request.'
and the Content-Type
header set to text/plain
. We're then printing out the response body to the console.
You can modify this example to use different HTTP methods (GET
, PUT
, DELETE
, etc.) and different content types as needed.
gistlibby LogSnag