【发布时间】: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