Net::HTTP URI.parse

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSasidaran
    New Member
    • Dec 2010
    • 4

    Net::HTTP URI.parse

    HI All,

    i am new to ROR

    i am writing Ruby code for calling API blogs

    i have written ruby code for

    creating a attachment xml by
    Code:
    require 'net/http'
    require 'uri'
    
    url = URI.parse('https://localhost:3000/api/attachment/create.xml')
    req = Net::HTTP::Post.new(url.path)
    req.basic_auth 'a', 'a'
    
    res = Net::HTTP.new(url.host, url.port).start {|http|
    http.request(req)}
    
    case res
      when Net::HTTPSuccess, Net::HTTPRedirection
        puts res.body
      else
        res.error!
    end
    Actually this works fine wth http protocol,

    My site is hosted in https protocol, can https protocol can be used in
    the below format. if i try to convert this kind of URL i get a error
    as

    SocketError: getaddrinfo: Temporary failure in name resolution

    plz help me in this
    Last edited by numberwhun; Jan 17 '11, 09:00 PM. Reason: Please use code tags!!!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    To parse an HTTPS connection, you are going to want to use:

    Code:
    require "net/https"
    There is an example on this cheat sheet page.

    There is also another example .

    Regards,

    Jeff

    Comment

    Working...