Failed to execute HTTP delete request in my ruby โ€‹โ€‹code using Net :: HTTP

Im using Net :: HTTP in my ruby โ€‹โ€‹code to execute http requests. For example, to make a send request, I do

require 'net/http' Net::HTTP.post_form(url,{'email' => email,'password' => password}) 

It works. But they failed to make a delete request, i.e.

 require 'net/http' Net::HTTP::Delete(url) 

gives the following error:

 NoMethodError: undefined method `Delete' for Net::HTTP:Class 

The documentation at http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html indicates that deletion is available. So why does this not work in my case?

thanks

+4
source share
3 answers

The documentation states that Net :: HTTP :: Delete is a class, not a method.

Try Net::HTTP.new('www.server.com').delete('/path') .

+5
source
 uri = URI('http://localhost:8080/customer/johndoe') http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Delete.new(uri.path) res = http.request(req) puts "deleted #{res}" 
+4
source

Simple send and delete requests, see docs for more:

 puts Net::HTTP.new("httpbin.org").post("/post", "a=1").body puts Net::HTTP.new("httpbin.org").delete("/delete").body 
0
source

Source: https://habr.com/ru/post/1438916/


All Articles