I wrote a code to send file as below:

Dim objXMLDoc As New XmlDocument

        objXMLDoc.Load("C:\Inetpub\wwwroot\XMLSchema_Test\XML\1773777.xml")

        Dim blnResponse As Boolean
        Dim objURI As Uri = New Uri("https://172.16.17.2/XMLSchema_Tests1/Web%20Forms/frmXML_Receive.aspx")
        Dim objWR As HttpWebRequest = HttpWebRequest.Create(objURI)
        blnResponse = objWR.HaveResponse
        Dim strXML As String = objXMLDoc.OuterXml
        objWR.Method = "POST"

        Dim encoding As New System.Text.ASCIIEncoding
        Dim btXMLLen() As Byte = encoding.UTF8.GetBytes(strXML)
        objWR.ContentLength = btXMLLen.Length
        objWR.KeepAlive = False
        Dim streamToSend As IO.Stream = objWR.GetRequestStream
        Dim strMessage As String
        Dim strStatus As String
        Dim blnConnect As Boolean
        Try
            streamToSend.Write(btXMLLen, 0, btXMLLen.Length)
            Dim objWebResponse As HttpWebResponse = objWR.GetResponse
            blnResponse = objWR.HaveResponse

        Catch ex As Web.HttpException
            strMessage = ex.Message

        Catch ex As IO.IOException
            strMessage = ex.Message

        Catch ex As Net.WebException
            strMessage = ex.Message

        End Try
        streamToSend.Close()

When I tried to send file to the URI stated above, the server throw the status 400 back to me when I tried to get the response from the server, and the https server doesn't receive any file. While I changed the URI to point to another server, which is a http server, the code works fine and able to send file to the server.

I would like to know why the code above is not able to send the file to the https server?

PS:

https://172.16.17.2/XMLSchema_Tests1/Web%20Forms/frmXML_Receive.aspx

The URI above is also the page that I developed. If I directly open the web page, there'll be a file dialog that enables
me to upload XML file. It works fine if I just upload a file in this way, but when I am using a function to send file to the
URI above, it does not works but it works fine on http server as I mentioned above.

Thanks in advanced.

I wrote a code to send file as below:

Dim objXMLDoc As New XmlDocument

        objXMLDoc.Load("C:\Inetpub\wwwroot\XMLSchema_Test\XML\1773777.xml")

        Dim blnResponse As Boolean
        Dim objURI As Uri = New Uri("https://172.16.17.2/XMLSchema_Tests1/Web%20Forms/frmXML_Receive.aspx")
        Dim objWR As HttpWebRequest = HttpWebRequest.Create(objURI)
        blnResponse = objWR.HaveResponse
        Dim strXML As String = objXMLDoc.OuterXml
        objWR.Method = "POST"

        Dim encoding As New System.Text.ASCIIEncoding
        Dim btXMLLen() As Byte = encoding.UTF8.GetBytes(strXML)
        objWR.ContentLength = btXMLLen.Length
        objWR.KeepAlive = False
        Dim streamToSend As IO.Stream = objWR.GetRequestStream
        Dim strMessage As String
        Dim strStatus As String
        Dim blnConnect As Boolean
        Try
            streamToSend.Write(btXMLLen, 0, btXMLLen.Length)
            Dim objWebResponse As HttpWebResponse = objWR.GetResponse
            blnResponse = objWR.HaveResponse

        Catch ex As Web.HttpException
            strMessage = ex.Message

        Catch ex As IO.IOException
            strMessage = ex.Message

        Catch ex As Net.WebException
            strMessage = ex.Message

        End Try
        streamToSend.Close()

When I tried to send file to the URI stated above, the server throw the status 400 back to me when I tried to get the response from the server, and the https server doesn't receive any file. While I changed the URI to point to another server, which is a http server, the code works fine and able to send file to the server.

I would like to know why the code above is not able to send the file to the https server?

PS:

https://172.16.17.2/XMLSchema_Tests1/Web%20Forms/frmXML_Receive.aspx

The URI above is also the page that I developed. If I directly open the web page, there'll be a file dialog that enables
me to upload XML file. It works fine if I just upload a file in this way, but when I am using a function to send file to the
URI above, it does not works but it works fine on http server as I mentioned above.

Thanks in advanced.

Just realized I insert the wrong URI, it should be https://172.16.17.2/XMLSchema_Tests/Web%20Forms/frmXML_Receive.aspx

Anyway, even I key in the URI correctly, and the server returns status 200, yet the server is unable to accept file, even there's no exception returns.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.