<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: https code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 17:41:54 GMT</pubDate>
    <description>DZone Snippets: https code</description>
    <item>
      <title>Getting Started With WWW::Mechanize</title>
      <link>http://snippets.dzone.com/posts/show/5134</link>
      <description>This Ruby code uses WWW:mechanize to act like a web browser.  &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; require 'rubygems'&lt;br /&gt; require 'mechanize'&lt;br /&gt;&lt;br /&gt; agent = WWW::Mechanize.new&lt;br /&gt; page = agent.get('http://google.com/')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Refer to the documentation at http://mechanize.rubyforge.org/mechanize/. Then gem install mechanize, and try running the code in an irb session.&lt;br /&gt;&lt;br /&gt;output (extract):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;=&gt; #&lt;WWW::Mechanize::Page&lt;br /&gt; {url #&lt;URI::HTTP:0xfdbbbb286 URL:http://www.google.com/&gt;}&lt;br /&gt; {meta}&lt;br /&gt; {title "Google"}&lt;br /&gt; {iframes}&lt;br /&gt; {frames}&lt;br /&gt; {links&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Images"&lt;br /&gt;   "http://images.google.com/imghp?hl=en&amp;tab=wi"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Maps"&lt;br /&gt;   "http://maps.google.com/maps?hl=en&amp;tab=wl"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "News"&lt;br /&gt;   "http://news.google.com/nwshp?hl=en&amp;tab=wn"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Shopping"&lt;br /&gt;   "http://www.google.com/prdhp?hl=en&amp;tab=wf"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Gmail"&lt;br /&gt;   "http://mail.google.com/mail/?hl=en&amp;tab=wm"&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 12 Feb 2008 17:53:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5134</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Make sure your site (or directory) is SSL encrypted</title>
      <link>http://snippets.dzone.com/posts/show/4405</link>
      <description>Need a simple way to make sure all http requests get redirected to https?&lt;br /&gt;This apache config snippet will redirect all requests at or below the specified location to its https equivilant.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;Location "/"&gt;&lt;br /&gt;        RewriteEngine on&lt;br /&gt;        Options +FollowSymLinks&lt;br /&gt;        Allow from all&lt;br /&gt;        RewriteCond %{SERVER_PORT} !^443$&lt;br /&gt;        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]&lt;br /&gt;&lt;/Location&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 09 Aug 2007 17:52:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4405</guid>
      <author>mikehale (Michael Hale)</author>
    </item>
    <item>
      <title>Use the del.icio.us API via HTTPS from Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2431</link>
      <description>Found at &lt;a href="http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/"&gt;http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/https'&lt;br /&gt;require "rexml/document"&lt;br /&gt;&lt;br /&gt;username = "" # your del.icio.us username&lt;br /&gt;password = "" # your del.icio.us password&lt;br /&gt;&lt;br /&gt;resp = href = "";&lt;br /&gt;begin      &lt;br /&gt;  http = Net::HTTP.new("api.del.icio.us", 443)&lt;br /&gt;  http.use_ssl = true&lt;br /&gt;  http.start do |http|&lt;br /&gt;    req = Net::HTTP::Get.new("/v1/tags/get", {"User-Agent" =&gt; &lt;br /&gt;        "juretta.com RubyLicious 0.2"})&lt;br /&gt;    req.basic_auth(username, password)&lt;br /&gt;    response = http.request(req)&lt;br /&gt;    resp = response.body&lt;br /&gt;  end     &lt;br /&gt;  #  XML Document&lt;br /&gt;  doc = REXML::Document.new(resp)    &lt;br /&gt;  # iterate over each element &lt;tag count="200" tag="Rails"/&gt;&lt;br /&gt;  doc.root.elements.each do |elem|&lt;br /&gt;    print elem.attributes['tag']  + " -&gt; " + elem.attributes['count'] + "\n"&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;rescue SocketError&lt;br /&gt;  raise "Host " + host + " nicht erreichbar"&lt;br /&gt;rescue REXML::ParseException =&gt; e&lt;br /&gt;  print "error parsing XML " + e.to_s&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 16 Aug 2006 21:37:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2431</guid>
      <author>jswizard (JavaScript Wizard)</author>
    </item>
    <item>
      <title>Custom HTTP/HTTPS GET/POST queries in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/788</link>
      <description>First, the scripts sends the GET query to read the website cookies (for session, etc.), and then it sends a POST query with the received cookies and custom POST parameters.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'net/https'&lt;br /&gt;&lt;br /&gt;http = Net::HTTP.new('profil.wp.pl', 443)&lt;br /&gt;http.use_ssl = true&lt;br /&gt;path = '/login.html'&lt;br /&gt;&lt;br /&gt;# GET request -&gt; so the host can set his cookies&lt;br /&gt;resp, data = http.get(path, nil)&lt;br /&gt;cookie = resp.response['set-cookie']&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# POST request -&gt; logging in&lt;br /&gt;data = 'serwis=wp.pl&amp;url=profil.html&amp;tryLogin=1&amp;countTest=1&amp;logowaniessl=1&amp;login_username=blah&amp;login_password=blah'&lt;br /&gt;headers = {&lt;br /&gt;  'Cookie' =&gt; cookie,&lt;br /&gt;  'Referer' =&gt; 'http://profil.wp.pl/login.html',&lt;br /&gt;  'Content-Type' =&gt; 'application/x-www-form-urlencoded'&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;resp, data = http.post(path, data, headers)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Output on the screen -&gt; we should get either a 302 redirect (after a successful login) or an error page&lt;br /&gt;puts 'Code = ' + resp.code&lt;br /&gt;puts 'Message = ' + resp.message&lt;br /&gt;resp.each {|key, val| puts key + ' = ' + val}&lt;br /&gt;puts data&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Thu, 06 Oct 2005 03:50:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/788</guid>
      <author>paulgoscicki (Paul Goscicki)</author>
    </item>
  </channel>
</rss>
