尝试发送POST
请求时遇到问题。发送方法如下所示:
Public Sub SendXML(ByVal file As String)
Dim reader As New StreamReader(file)
Dim data As String = reader.ReadToEnd()
reader.Close()
Dim request As HttpWebRequest = WebRequest.Create("http://blah/Request")
request.Method = "POST"
System.Net.ServicePointManager.Expect100Continue = False
Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(data)
request.ContentLength = bytes.Length
Dim oStreamOut As Stream = request.GetRequestStream()
oStreamOut.Write(bytes, 0, bytes.Length)
oStreamOut.Close()
Dim response As HttpWebResponse = request.GetResponse()
End Sub
运行此程序时,我收到上述错误。通过 Fiddler 我可以看到请求看起来像:
POST http://blah/Request HTTP/1.1
Host: blah
Content-Length: 322
Proxy-Connection: Keep-Alive
<?xml version="1.0"?>
<Envelope>
<Header>
<UserID>uid</UserID>
<Password>pass</Password>
<SessionID />
<RequestType>GetDetails</RequestType>
<POSCompany>01</POSCompany>
<PackageType>DATA</PackageType>
<ActionType>READ</ActionType>
<SnoopUserID />
</Header>
<Body>
<MagicNumber>124</MagicNumber>
</Body>
</Envelope>
现在看这个我怀疑这是由于服务器不接受POST
消息的事实。但是其他一些阅读表明 URIhttp://blah/Request
是使用代理生成的,应该是/Request
这样的行应该是POST /Request HTTP/1.1
那么常见的原因是什么?如果是代理问题,如何排序?
如下所述,我为更具体的请求创建了一个新问题。在 HTTP POST 标头中将绝对 URI 更改为相对