Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2780 > unrolled thread

HTTP request, with headers, post data and SSL :(

Started by"Stuffe L." <stuffe.dk@gmail.com>
First post2011-04-13 14:11 -0500
Last post2011-04-14 12:56 -0500
Articles 5 — 3 participants

Back to article view | Back to comp.lang.ruby


Contents

  HTTP request, with headers, post data and SSL :( "Stuffe L." <stuffe.dk@gmail.com> - 2011-04-13 14:11 -0500
    Re: HTTP request, with headers, post data and SSL :( Oscar Sosa <oscar.americo@gmail.com> - 2011-04-13 18:28 -0500
    Re: HTTP request, with headers, post data and SSL :( 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-13 18:44 -0500
    Re: HTTP request, with headers, post data and SSL :( "Stuffe L." <stuffe.dk@gmail.com> - 2011-04-14 03:33 -0500
      Re: HTTP request, with headers, post data and SSL :( 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-14 12:56 -0500

#2780 — HTTP request, with headers, post data and SSL :(

From"Stuffe L." <stuffe.dk@gmail.com>
Date2011-04-13 14:11 -0500
SubjectHTTP request, with headers, post data and SSL :(
Message-ID<cc8c045fb2e91f082249ef47f97aaec8@ruby-forum.com>
Hello everyone

I am new to ruby and have been struggeling with this http api thing. I
need to do a request with certian request headers, certain post
variables and SSL.
I got it to work with SSL and the headers, but I just cant get it to
work when i try to cenvert it to post. Very frustrating.

Heres how far i got (this is without post, which i couldnt get to work):

  post_me = 'xml data'

  headers = {'Header' => 'Whatever'}
  uri = URI.parse("https://example.com")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = http.post(uri.request_uri, get_string, headers)

Any help very much apreciated

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#2795

FromOscar Sosa <oscar.americo@gmail.com>
Date2011-04-13 18:28 -0500
Message-ID<BANLkTi=mHeaUu474RhDbPj5VpHwSfL4_+A@mail.gmail.com>
In reply to#2780
[Note:  parts of this message were removed to make it a legal post.]

Hi.

You can try Mechanize, it works for me like a charm.

On Wed, Apr 13, 2011 at 2:11 PM, Stuffe L. <stuffe.dk@gmail.com> wrote:

> Hello everyone
>
> I am new to ruby and have been struggeling with this http api thing. I
> need to do a request with certian request headers, certain post
> variables and SSL.
> I got it to work with SSL and the headers, but I just cant get it to
> work when i try to cenvert it to post. Very frustrating.
>
> Heres how far i got (this is without post, which i couldnt get to work):
>
>  post_me = 'xml data'
>
>  headers = {'Header' => 'Whatever'}
>  uri = URI.parse("https://example.com")
>  http = Net::HTTP.new(uri.host, uri.port)
>  http.use_ssl = true
>  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
>  response = http.post(uri.request_uri, get_string, headers)
>
> Any help very much apreciated
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


-- 
Oscar Sosa

[toc] | [prev] | [next] | [standalone]


#2799

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-13 18:44 -0500
Message-ID<e3038966ef38586a68f36136a45c4063@ruby-forum.com>
In reply to#2780
Stuffe L. wrote in post #992584:
> Hello everyone
>
> I am new to ruby and have been struggeling with this http api thing. I
> need to do a request with certian request headers, certain post
> variables and SSL.
> I got it to work with SSL and the headers, but I just cant get it to
> work when i try to cenvert it to post. Very frustrating.
>
> Heres how far i got (this is without post, which i couldnt get to work):
>
>   post_me = 'xml data'
>
>   headers = {'Header' => 'Whatever'}
>   uri = URI.parse("https://example.com")
>   http = Net::HTTP.new(uri.host, uri.port)
>   http.use_ssl = true
>   http.verify_mode = OpenSSL::SSL::VERIFY_NONE
>   response = http.post(uri.request_uri, get_string, headers)
>
> Any help very much apreciated

1) In that code get_string is undefined.
2) In that code there are no require statements requiring the necessary 
libraries.

See if you can get this to work:

require 'net/http'
require 'net/https'
require 'uri'

url = URI.parse('https://www.some_host.com/some_path_to/page.htm')

http = Net::HTTP.new(url.host)
http.use_ssl = true

data = "a=1&b=2&c=3"

headers = {
  'Cookie' => cookie,
  'Referer' => 'http://profil.wp.pl/login.html',
  'Content-Type' => 'application/x-www-form-urlencoded'
}

resp = http.post(url.path, data, headers)
puts resp.body

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#2834

From"Stuffe L." <stuffe.dk@gmail.com>
Date2011-04-14 03:33 -0500
Message-ID<37358189582d77c8623a61e4263aa893@ruby-forum.com>
In reply to#2780
@7stud, I copied the code out of a function and tried to simplify it for 
you guys to read :) But I must have forgot what you said.
But if you do as in your example, the contents of the data variable will 
be send as a part of the query string no? Therefore it will still a get 
and I know that works sometimes, but in this particular case it MUST be 
post!

@Oscar Will, do later today! Thanks.

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#2865

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-14 12:56 -0500
Message-ID<0cfccd79e95056977aef1235d17dbb75@ruby-forum.com>
In reply to#2834
Stuffe L. wrote in post #992713:
> @7stud, I copied the code out of a function and tried to simplify it for
> you guys to read :) But I must have forgot what you said.
> But if you do as in your example, the contents of the data variable will
> be send as a part of the query string no?

No.  This line:

resp = http.post(url.path, data, headers)

tells ruby to send a *post* request.  POST requests do not include data 
in the query string--they put the data in the body of the request.  The 
data still has to be in an agreed upon format, though, otherwise the 
other side won't know how to split it up to make sense of the data.

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web