当我使用以下代码调用 restful 服务时,出现错误
底层连接已关闭:接收时发生意外错误。
代码:
Const url As String = "http://localhost:8003/Tracker/Tracker.svc/GetTrackerDetails"
ServicePointManager.MaxServicePointIdleTime = 500
ServicePointManager.UseNagleAlgorithm = True
ServicePointManager.Expect100Continue = True
ServicePointManager.CheckCertificateRevocationList = True
ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit
req = DirectCast(WebRequest.Create(url), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/xml; charset=utf-8"
req.Timeout = 300000
req.KeepAlive = False
req.Headers.Add("SOAPAction", url)
Dim xmlDoc = New XmlDocument With {.XmlResolver = Nothing}
xmlDoc.Load(Server.MapPath("Request.xml"))
Dim sXml As String = xmlDoc.InnerXml
req.ContentLength = sXml.Length
Dim sw = New StreamWriter(req.GetRequestStream())
sw.Write(sXml)
sw.Close()
res = DirectCast(req.GetResponse(), HttpWebResponse)
Dim responseStream As Stream = res.GetResponseStream()
Dim streamReader = New StreamReader(responseStream)
'Read the response into an xml document
Dim soapResonseXmlDocument = New XmlDocument()
soapResonseXmlDocument.LoadXml(streamReader.ReadToEnd())
TextBox1.Text = Server.HtmlDecode(soapResonseXmlDocument.InnerXml)
soapResonseXmlDocument.LoadXml(TextBox1.Text)
在过去的几天里,我面临着这个错误。我的调用代码有什么问题。请帮帮我。