I am trying to test a rest webservice but when I do a post and try to retreive the save the response stream to a file I get an exception saying "Stream was not readable." What am I doing wrong?
Public Sub PostAndRead()
Dim flReader As FileStream = New FileStream("~\testRequest.xml", FileMode.Open, FileAccess.Read)
Dim flWriter As FileStream = New FileStream("~\testResponse.xml", FileMode.Create, FileAccess.Write)
Dim address As Uri = New Uri(restAddress)
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(address), HttpWebRequest)
req.Method = "POST"
req.ContentLength = flReader.Length
req.AllowWriteStreamBuffering = True
Dim reqStream As Stream = req.GetRequestStream()
' Get data from upload file to inData
Dim inData(flReader.Length) As Byte
flReader.Read(inData, 0, flReader.Length)
' put data into request stream
reqStream.Write(inData, 0, flReader.Length)
flReader.Close()
reqStream.Close()
' Post Response
req.GetResponse()
' Save results in a file
Copy(req.GetRequestStream(), flWriter)
End Sub