Adding a header into a HTTP post request

G

Giacecco

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
 
C

coachhilton

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
 
R

Robert Klemme

Giacecco said:
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
 
R

Robert Klemme

Giacecco said:
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
 
G

Giacecco

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top