[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Adding a header into a HTTP post request

Giacecco

4/11/2006 4:32:00 PM

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/envel...
xmlns:xsd="http://www.w3.org/2001/XMLSc...
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

4 Answers

coachhilton

4/11/2006 6:16:00 PM

0

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

Robert Klemme

4/12/2006 7:08:00 AM

0

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.ht...

robert

Robert Klemme

4/12/2006 7:08:00 AM

0

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.ht...

robert

Giacecco

4/12/2006 3:34:00 PM

0

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