【问题标题】:How to set SOAP version using HttpWebRequest如何使用 HttpWebRequest 设置 SOAP 版本
【发布时间】:2019-05-31 13:35:12
【问题描述】:

我在尝试发送以下 WSDL 时收到“(415) 不支持的媒体类型”:

Dim xml1 As String = String.Empty
xml1 = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" "
xml1 += "xmlns:ser=""http://client_server.com/"">"
xml1 += "<soapenv:Header/>"
xml1 += "<soapenv:Body>"
xml1 += "XML_CONTENT"
xml1 += "</soapenv:Body>"
xml1 += "</soapenv:Envelope>"
'----------------------------
Dim a As New System.Text.ASCIIEncoding()
Dim buffer As Byte() = a.GetBytes(xml1)
Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://server.com?wsdl"), HttpWebRequest)
request.ServicePoint.Expect100Continue = False
request.KeepAlive = False
request.Headers.Add("SOAPAction", "")
request.Method = "POST"
request.ContentType = "application/soap+xml; charset=""UTF-8"""
request.Accept = "text/xml"
Dim stm As Stream = request.GetRequestStream()
stm.Write(buffer, 0, buffer.Length)
stm.Close()
Dim resp As WebResponse = request.GetResponse()
stm = resp.GetResponseStream()

据我了解,异常的原因是服务器使用的 SOAP 版本(“1.1”)与我请求的版本(“1.2”,我猜)不同。 如何设置 SOAP 版本? 或者有没有其他方法可以解决这个“不支持的媒体类型”错误?

【问题讨论】:

    标签: vb.net soap httpwebrequest


    【解决方案1】:

    它通过删除我填充“ContentType”属性的行(“request.ContentType = “application/soap+xml;charset=UTF-8”)来工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多