Changing absolute URI to relative in HTTP POST header

江枫思渺然 提交于 2019-12-25 03:55:18

问题


I have the following POST request:

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>

This is failing with the error - (405) Method not supported

An example XML which apparently works on the server is the same but the header has the line POST /Request HTTP/1.1 instead of POST http://blah/Request HTTP/1.1.

I don't know if this is the problem but I am trying to eliminate all possibilites. However, I cannot get the POST request URI to be relative and not absolute. Is there a wat to do this?

The following is the code used for sending the 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

Asked here in response to a request at 405 - Method Not Allowed HttpWebRequest


回答1:


Following HTTP Error 405 Method not allowed

405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.



来源:https://stackoverflow.com/questions/10030141/changing-absolute-uri-to-relative-in-http-post-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!