Adding a header into a HTTP post request

Discussion in 'Ruby' started by Giacecco, Apr 11, 2006.

  1. Giacecco

    Giacecco Guest

    Dear all,
    I am trying to manually build a soap envelope to call a web service,
    because I cannot use soap4r: it has some strange compatibility problems
    when interfacing my Oracle BPEL Process Manager.

    My code is the following, and I think it is quite ok. I am only missing
    how to set custom http headers in the request. I believe I need to set
    "Content-Type" to "text/xml" and "SOAPAction" to "initiate. Please
    help!

    Gianfranco



    require 'net/http'

    Net::HTTP.start('whatever', 7777) do |http|
    postString = '<?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    (...)
    </soapenv:Body>
    </soapenv:Envelope>'
    response = http.post2('/whatever', postString)
    case response
    when Net::HTTPSuccess
    puts 'Ok!'
    else
    response.error!
    end
    end
     
    Giacecco, Apr 11, 2006
    #1
    1. Advertising

  2. Giacecco

    Guest

    I'd check out http.rb. The method binding for post2 includes an
    optional initheader argument. Not sure it this is what you need but it
    sounds like it.

    Ken
     
    , Apr 11, 2006
    #2
    1. Advertising

  3. Giacecco wrote:
    > Dear all,
    > I am trying to manually build a soap envelope to call a web service,
    > because I cannot use soap4r: it has some strange compatibility problems
    > when interfacing my Oracle BPEL Process Manager.
    >
    > My code is the following, and I think it is quite ok. I am only missing
    > how to set custom http headers in the request. I believe I need to set
    > "Content-Type" to "text/xml" and "SOAPAction" to "initiate. Please
    > help!


    The documentation doesn't explain parameter "initheader" but it sounds
    as if that could be what you need:

    http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html#M000681

    robert
     
    Robert Klemme, Apr 12, 2006
    #3
  4. Giacecco wrote:
    > Dear all,
    > I am trying to manually build a soap envelope to call a web service,
    > because I cannot use soap4r: it has some strange compatibility problems
    > when interfacing my Oracle BPEL Process Manager.
    >
    > My code is the following, and I think it is quite ok. I am only missing
    > how to set custom http headers in the request. I believe I need to set
    > "Content-Type" to "text/xml" and "SOAPAction" to "initiate. Please
    > help!


    The documentation doesn't explain parameter "initheader" but it sounds
    as if that could be what you need:

    http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html#M000681

    robert
     
    Robert Klemme, Apr 12, 2006
    #4
  5. Giacecco

    Giacecco Guest

    It was very easy in the end: you can add whatever http header you want
    as the third parameter in post2 as in the following...

    response = http.post2('/whatever', postString, {'Content-Type' =>
    'text/xml', 'SOAPAction' => 'initiate'})

    Thank you all for your help. Is it just me, or the Ruby documentation
    is a bit weak?

    Gianfranco
     
    Giacecco, Apr 12, 2006
    #5
    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:
    4
    Views:
    1,049
    Juan T. Llibre
    Jul 26, 2005
  2. Replies:
    6
    Views:
    5,962
    Tor Iver Wilhelmsen
    Aug 29, 2005
  3. James
    Replies:
    3
    Views:
    16,555
    Roedy Green
    Nov 25, 2005
  4. Matias Surdi

    Adding a HTTP header to a SOAPpy request

    Matias Surdi, Jan 3, 2008, in forum: Python
    Replies:
    3
    Views:
    1,121
    sharonxi1205
    Jun 21, 2011
  5. cerr
    Replies:
    1
    Views:
    147
    Piet van Oostrum
    Aug 16, 2013
Loading...

Share This Page