Domanda

I use the following code to pass data into a website:

require "net/http"
params = {"message"=>"some message", "to"=>"someone"}
Net::HTTP.post_form(URI.parse("http://example.com/m/send"),params)

When I inspect the web page, the form action is http://example.com/m/send and I can post the data using the site itself without any problem.

I keep getting HTTP 404 and my data is not passed to the database.

When I request the page with GET method, then I get HTTP 405, which is an unauthorized request error. This guarantees that the page exists.

Since the url is valid, what would prevent the data being posted? And how can I fix that?

È stato utile?

Soluzione

I could not solve the question using Net/HTTP library solely; however, Mechanize gem as Tin Man suggested in the comments solves the problem and successfully posts the data into the server.

It is also more flexible and easier in terms of following redirection. Hence, if anyone runs into this problem like I did, I recommend them using the Mechanize gem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top