Savon change Content-Type header

689 views
Skip to first unread message

Mark Zweedijk

unread,
Mar 15, 2012, 8:51:48 AM3/15/12
to sav...@googlegroups.com

I'm setting up a soap request. I get it so fare that the xml is perfect, but the problem is the header. My SOAP-service wants in the header "text/xml; charset=utf-8" but savon makes "soap+xml; charset=utf-8" of it. When I try to change the header, it ignores my code.

Here's my code:

client = Savon::Client.new do
    wsdl.document = "someservice.svc?wsdl"
    http.auth.basic user, password
    http.headers["Content-Type"] = "text/xml; charset=utf-8"
    http.headers["Content-Encoding"] = "gzip"
  end

response = client.request :ser, "ACKUserServiceReadRequest" do |soap|
    soap.version = 2
    soap.namespaces.merge!({
        "xmlns:ser"   => "http://schemas.microsoft.com/dynamics/2008/01/services",
        "xmlns:ent"   => "http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList",
        "xmlns:ent1"  => "http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey",
        "xmlns:env"   => "http://schemas.xmlsoap.org/soap/envelope/"
      })
    soap.body = "<ent:EntityKeyList><ent1:EntityKey><ent1:KeyData><ent1:KeyField><ent1:Field>NetworkAlias</ent1:Field><ent1:Value>MichaelA</ent1:Value></ent1:KeyField></ent1:KeyData></ent1:EntityKey></ent:EntityKeyList>"
  end
When I execute he adds the content-encoding but doesn't change the content-length. This output I get: SOAPAction: "ACKUserServiceReadRequest", Content-Type: application/soap+xml;charset=UTF-8, Content-Length: 734, Content-Encoding: gzip

Mark Zweedijk

unread,
Mar 16, 2012, 4:15:17 AM3/16/12
to sav...@googlegroups.com
I fixt the problem. The problem was the soap.version. When you set soap.version to 2, then your content-type is "soap/xml; charset=utf-8". When soap.version is 1, "text/xml; charset=utf-8". 

Op donderdag 15 maart 2012 13:51:48 UTC+1 schreef Mark Zweedijk het volgende:
Reply all
Reply to author
Forward
0 new messages