在HTTP POST标头中将绝对URI更改为relative

时间:2012-04-05 14:05:18

标签: vb.net post httpwebrequest http-headers

我有以下POST请求:

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>

失败并出现错误 - (405)方法不支持

显然在服务器上运行的示例XML是相同的,但标题包含行POST /Request HTTP/1.1而不是POST http://blah/Request HTTP/1.1

我不知道这是不是问题,但我试图消除所有可能性。但是,我无法将POST请求URI设置为相对而非绝对。是否有扫管笏才能做到这一点?

以下是用于发送XML的代码。

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

在这里回答405 - Method Not Allowed HttpWebRequest

的请求

1 个答案:

答案 0 :(得分:0)

关注HTTP Error 405 Method not allowed

  

POST方法经常出现405错误。你可能会尝试   在网站上引入某种输入形式,但不是所有的ISP   允许处理表单所需的POST方法。

     

所有405错误都可以追溯到Web服务器的配置和   安全管理访问网站的内容,所以应该   很容易通过您的ISP解释。