0
呃,我不断收到一个ProtocolViolationException“要写入流的字节超过指定的Content-Length字节大小。在下面的代码。Vb.Net - 写入的字节超过XML中的内容长度字节
我试过设置Content-Length多种方式没有成功。
Dim url = "https://domain.com"
Dim req As WebRequest = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/xml"
Dim utf8 As New UTF8Encoding()
req.ContentLength = utf8.GetByteCount(xml.OuterXml)
xml.Save(req.GetRequestStream()) // throws the exception
req.GetRequestStream().Close()
Dim httpResp As WebResponse = req.GetResponse()
Dim stReader As StreamReader = New StreamReader(httpResp.GetResponseStream())
Dim strResponse As String
strResponse = stReader.ReadToEnd()
Console.WriteLine(strResponse)
我试过设置使用xml.OutXML.Length
如果您省略行,会发生什么情况:req.ContentLength = utf8.GetByteCount(xml.OuterXml)? – CarneyCode 2011-02-19 07:07:59
该API要求我发送有效的Content-Length标头。 – doremi 2011-02-19 07:13:03