Im looking for a very very basic POST form that will post data to an external website with Net:http I wonder if anyone has created one they could share? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Im looking for a very very basic POST form that will post data to an > external website with Net:http > > I wonder if anyone has created one they could share?From... http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html Posting Form Data require ''net/http'' require ''uri'' #1: Simple POST res = Net::HTTP.post_form(URI.parse(''http://www.example.com/search.cgi''), {''q''=>''ruby'', ''max''=>''50''}) puts res.body #2: POST with basic authentication res = Net::HTTP.post_form(URI.parse(''http://jack:pass-NCzvY20eV+mnzT0iUeSTvQ@public.gmane.org/todo.cgi''), {''from''=>''2005-01-01'', ''to''=>''2005-03-31''}) puts res.body #3: Detailed control url = URI.parse(''http://www.example.com/todo.cgi'') req = Net::HTTP::Post.new(url.path) req.basic_auth ''jack'', ''pass'' req.set_form_data({''from''=>''2005-01-01'', ''to''=>''2005-03-31''}, '';'') res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } case res when Net::HTTPSuccess, Net::HTTPRedirection # OK else res.error! end Or did you mean something else? -philip -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This is what I have used a few times. Error handling my own. def self.post_data(url, post_data) resp = "" begin url = URI.parse(url) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.port == 443 http.start do |http| req = Net::HTTP::Post.new(url.path) req.set_body_internal(post_data) response = http.request(req) resp = response.body end rescue Exception => e @response_error = e error = SystemError.new(:user_id => nil, :account_id => nil, :location => "GlobalFunctions.post_data", :error => "#{e}", :incidentals => {"url" => url, "post_data" => post_data} ).save end resp end On Wed, Sep 15, 2010 at 2:31 AM, Crooksey <crooksey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Im looking for a very very basic POST form that will post data to an > external website with Net:http > > I wonder if anyone has created one they could share? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Crooksey wrote:> Im looking for a very very basic POST form that will post data to an > external website with Net:httpYou don''t need Net::HTTP to do that. Just set the form''s action to an external URL.> > I wonder if anyone has created one they could share?Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.