I am trying to use this method to post a form. The problem is that the set_form_data method sets Content-Type: header field to application/x-www-form-urlencoded. I need it to be application/xml. I tried the set_content_type_method(''application/xml''), but it did not seem to help. Here is my code url = URI.parse(''http://192.168.0.248/putxml'') req = Net::HTTP::Post.new(url.path) req.basic_auth ''admin'', ''pass'' req.set_form_data(''<Command><Dial><Number>192.168.0.122</Number></Dial></Command>'') 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 Can someone please help me. I don''t need to use this method. I can get it what I want by typing this at the command line. curl -H "Content-Type: application/xml" -X POST -d "<Command><Dial><Number>192.168.0.248</Number></Dial></Number>" http://admin:pass-Q0ErXNX1RuZo5tW0rUFMbQ@public.gmane.org/putxml Thanks -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can just pass a hash representing an HTTP header to the request method. "Content-Type" => "application/x-www-form-urlencoded". On 1/5/07, John F <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I am trying to use this method to post a form. > The problem is that the set_form_data method sets Content-Type: header > field to application/x-www-form-urlencoded. I need it to be > application/xml. > I tried the set_content_type_method(''application/xml''), but it did not > seem to help. > Here is my code > url = URI.parse(''http://192.168.0.248/putxml'') > req = Net::HTTP::Post.new(url.path) > req.basic_auth ''admin'', ''pass'' > req.set_form_data(''<Command><Dial><Number>192.168.0.122 > </Number></Dial></Command>'') > 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 > > Can someone please help me. I don''t need to use this method. > I can get it what I want by typing this at the command line. > curl -H "Content-Type: application/xml" -X POST -d > "<Command><Dial><Number>192.168.0.248</Number></Dial></Number>" > http://admin:pass-Q0ErXNX1RuZo5tW0rUFMbQ@public.gmane.org/putxml > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Correction, to the POST/GET methods. On 1/5/07, John F <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I am trying to use this method to post a form. > The problem is that the set_form_data method sets Content-Type: header > field to application/x-www-form-urlencoded. I need it to be > application/xml. > I tried the set_content_type_method(''application/xml''), but it did not > seem to help. > Here is my code > url = URI.parse(''http://192.168.0.248/putxml'') > req = Net::HTTP::Post.new(url.path) > req.basic_auth ''admin'', ''pass'' > req.set_form_data(''<Command><Dial><Number>192.168.0.122 > </Number></Dial></Command>'') > 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 > > Can someone please help me. I don''t need to use this method. > I can get it what I want by typing this at the command line. > curl -H "Content-Type: application/xml" -X POST -d > "<Command><Dial><Number>192.168.0.248</Number></Dial></Number>" > http://admin:pass-Q0ErXNX1RuZo5tW0rUFMbQ@public.gmane.org/putxml > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John F wrote:> I am trying to use this method to post a form. > The problem is that the set_form_data method sets Content-Type: header > field to application/x-www-form-urlencoded. I need it to be > application/xml. > I tried the set_content_type_method(''application/xml''), but it did not > seem to help. > Here is my code > url = URI.parse(''http://192.168.0.248/putxml'') > req = Net::HTTP::Post.new(url.path) > req.basic_auth ''admin'', ''pass'' > req.set_form_data(''<Command><Dial><Number>192.168.0.122</Number></Dial></Command>'')# These two additional statements "do it for me" # set_form_data sets the content_type so we set it to what we need req.content_type = ''application/x-www-form-urlencoded'' # add_field prepends HTTP_ req.add_field ''X_REQUESTED_WITH'', ''XMLHttpRequest''> 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 >Stephan -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---