simple HTTP Post Xml request

Discussion in 'Ruby' started by Me Me, Feb 10, 2009.

  1. Me Me

    Me Me Guest

    Hi,
    I'm trying to post a xml to a server for encoding a file
    (http://www.encoding.com/wdocs/SampleScripts).

    Basically I just need a simple HTTP post where I specify an xml.
    I'm trying to use Net::HTTP post but in my case I don't have a path to
    specify as first parameter.
    I jut need to send HTTP(S) POST request with single parameter named xml.
    The server response is a normal XML document.

    Thanks for any help on this.
    Bye
    --
    Posted via http://www.ruby-forum.com/.
     
    Me Me, Feb 10, 2009
    #1
    1. Advertising

  2. Me Me

    7stud -- Guest

    Me Me wrote:
    > Hi,
    > 1) I'm trying to post a xml to a server....
    >
    > 2)but in my case I don't have a path to
    > specify as first parameter.


    Those are incompatible statements. Servers live somewhere on the net,
    and therefore they have url's that identify their location.

    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Feb 10, 2009
    #2
    1. Advertising

  3. Me Me

    Dylan Evans Guest

    [Note: parts of this message were removed to make it a legal post.]

    On Tue, Feb 10, 2009 at 8:21 PM, Me Me <> wrote:

    > Hi,
    > I'm trying to post a xml to a server for encoding a file
    > (http://www.encoding.com/wdocs/SampleScripts).
    >
    > Basically I just need a simple HTTP post where I specify an xml.
    > I'm trying to use Net::HTTP post but in my case I don't have a path to
    > specify as first parameter.
    > I jut need to send HTTP(S) POST request with single parameter named xml.
    > The server response is a normal XML document.
    >


    If the http server doesn't care about the path can't you just use any? such
    as '/'

    --
    The UNIX system has a command, nice ... in order to be nice to the other
    users. Nobody ever uses it." - Andrew S. Tanenbaum
     
    Dylan Evans, Feb 10, 2009
    #3
  4. Me Me

    Me Me Guest

    thanks for answering.

    I tried:

    require 'net/http'
    require 'rexml/document'

    url='http://manage.encoding.com/'
    http=Net:HTTP.new(url)
    xml_response = http.post('/','')

    and I get
    getaddrinfo: no address associated with hostname (Socket Error)
    --
    Posted via http://www.ruby-forum.com/.
     
    Me Me, Feb 10, 2009
    #4
  5. Me Me

    7stud -- Guest

    Me Me wrote:
    > thanks for answering.
    >
    > I tried:
    >
    > require 'net/http'
    > require 'rexml/document'
    >
    > url='http://manage.encoding.com/'
    > http=Net:HTTP.new(url)
    > xml_response = http.post('/','')
    >
    > and I get
    > getaddrinfo: no address associated with hostname (Socket Error)



    >>The server response is a normal XML document.


    Where is "the server" that you are referring to? And by "where" I mean
    what is its url?
    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Feb 10, 2009
    #5
  6. Me Me

    lasitha Guest

    On Tue, Feb 10, 2009 at 4:52 PM, Me Me <> wrote:
    > I tried:
    >
    > url='http://manage.encoding.com/'
    > http=Net:HTTP.new(url)
    > xml_response = http.post('/','')
    >
    > and I get
    > getaddrinfo: no address associated with hostname (Socket Error)


    With the disclaimer than i haven't used net/http much, the following
    three forms all seem to post to manage.encoding.com and get back a 200
    OK response.


    require 'net/http'
    require 'uri'

    # this is the closest form to the one you tried
    # note that the http protocol is excluded
    # (presumably because we're explicitly constructing an HTTP object)

    http = Net::HTTP.new('manage.encoding.com')
    response = http.post('/', "xml=#{some_xml_data}")


    # this form uses the post_form class method and a parsed uri
    # note the trailing slash is necessary
    # note also the (cleaner) use of a hash over a string for post params

    url = URI.parse('http://manage.encoding.com/')
    response = Net::HTTP.post_form(url, { 'xml' => some_xml_data })


    # this form opens the tcp connection and http session,
    # ensuring they are closed after the block executes

    url = URI.parse('http://manage.encoding.com/')
    Net::HTTP.start(url.host, url.port) do |http|
    response = http.post(url.path, "xml=#{some_xml_data}")
    end


    HTH,
    lasitha
     
    lasitha, Feb 10, 2009
    #6
  7. Me Me

    Me Me Guest


    > # this is the closest form to the one you tried
    > # note that the http protocol is excluded
    > # (presumably because we're explicitly constructing an HTTP object)
    >
    > http = Net::HTTP.new('manage.encoding.com')
    > response = http.post('/', "xml=#{some_xml_data}")
    >


    Thanks a lot !!!
    This is really what I needed.
    --
    Posted via http://www.ruby-forum.com/.
     
    Me Me, Feb 10, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    6,047
    Tor Iver Wilhelmsen
    Aug 29, 2005
  2. James
    Replies:
    3
    Views:
    16,616
    Roedy Green
    Nov 25, 2005
  3. Matt
    Replies:
    5
    Views:
    411
    Aaron Bertrand - MVP
    May 4, 2004
  4. scootiePuff
    Replies:
    4
    Views:
    235
    Rilindo Foster
    Aug 21, 2009
  5. Erik Wasser
    Replies:
    5
    Views:
    515
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page