Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > HTTP request, with headers, post data and SSL :(

Reply
Thread Tools

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

 
 
Stuffe L.
Guest
Posts: n/a
 
      04-13-2011
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/.

 
Reply With Quote
 
 
 
 
Oscar Sosa
Guest
Posts: n/a
 
      04-13-2011
[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. <> 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

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      04-13-2011
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/.

 
Reply With Quote
 
Stuffe L.
Guest
Posts: n/a
 
      04-14-2011
@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/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      04-14-2011
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Http post and http get n3d!m Python 2 02-06-2012 09:18 PM
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
Why getInputStream in a http servlet request isn't getting the datasent by browser HTTP POST action? James Java 3 11-25-2005 11:17 PM
HTTP GET vs HTTP POST protocol serge calderara ASP .Net Web Services 1 11-04-2005 01:27 PM
How to enter to .aspx page by http connection using http POST request farazkazmi@gmail.com Java 6 08-29-2005 02:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57