Hi,
I am trying to upload test.txt file to remote server through HTTPS protocol.
for that on button click I have write the code as follows:
Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUploadFile.Click
UploadFile("c:\test.txt", "https://remotemachine.com/test/files/")
End Sub
Public Sub UploadFile(ByVal localFile As String, ByVal uploadUrl As String)
Try
Dim req As HttpWebRequest
req = CType(WebRequest.Create(uploadUrl), HttpWebRequest)
req.KeepAlive = True
req.Credentials = New NetworkCredential("userName", "password")
req.ContentType = "Content-Type: multipart/form-data; boundary=BOUNDRY"
req.Method = "POST"
req.AllowWriteStreamBuffering = True
Dim reqStream As Stream
reqStream = req.GetRequestStream()
Dim rdr As New FileStream(localFile, FileMode.Open)
Dim inData(4096) As Byte
Dim bytesRead = rdr.Read(inData, 0, inData.Length - 1)
While bytesRead > 0
reqStream.Write(inData, 0, bytesRead)
bytesRead = rdr.Read(inData, 0, inData.Length - 1)
End While
rdr.Close()
reqStream.Close()
Dim objWebResponse As System.Net.HttpWebResponse
objWebResponse = CType(req.GetResponse, HttpWebResponse)
Catch ex As WebException
MsgBox("Error Message:" + ex.Message)
Finally
End Try
End Sub
But it raises an exception at
objWebResponse = CType(req.GetResponse, HttpWebResponse)
with message : The remote server returned an error : (405) Method Not Allowed
Can anyone please let me know as to how can i overcome this issue.
I am trying to upload test.txt file to remote server through HTTPS protocol.
for that on button click I have write the code as follows:
Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUploadFile.Click
UploadFile("c:\test.txt", "https://remotemachine.com/test/files/")
End Sub
Public Sub UploadFile(ByVal localFile As String, ByVal uploadUrl As String)
Try
Dim req As HttpWebRequest
req = CType(WebRequest.Create(uploadUrl), HttpWebRequest)
req.KeepAlive = True
req.Credentials = New NetworkCredential("userName", "password")
req.ContentType = "Content-Type: multipart/form-data; boundary=BOUNDRY"
req.Method = "POST"
req.AllowWriteStreamBuffering = True
Dim reqStream As Stream
reqStream = req.GetRequestStream()
Dim rdr As New FileStream(localFile, FileMode.Open)
Dim inData(4096) As Byte
Dim bytesRead = rdr.Read(inData, 0, inData.Length - 1)
While bytesRead > 0
reqStream.Write(inData, 0, bytesRead)
bytesRead = rdr.Read(inData, 0, inData.Length - 1)
End While
rdr.Close()
reqStream.Close()
Dim objWebResponse As System.Net.HttpWebResponse
objWebResponse = CType(req.GetResponse, HttpWebResponse)
Catch ex As WebException
MsgBox("Error Message:" + ex.Message)
Finally
End Try
End Sub
But it raises an exception at
objWebResponse = CType(req.GetResponse, HttpWebResponse)
with message : The remote server returned an error : (405) Method Not Allowed
Can anyone please let me know as to how can i overcome this issue.