0

I am creating a stream from an excel file, and need to post it to a web service. When I try 'MsgBox objStream.Size' it will give me the full file size, but after I post to my service and check the length of the stream, it is 0. Am I sending the POST correctly?

Sub postStreamToService()
    Dim oRequest As Object
    Dim objStream As ADODB.stream
    Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    Set objStream = New ADODB.stream
    objStream.Open
    objStream.LoadFromFile "C:\Users\Desktop\excel\test.xls"
    oRequest.Open "POST", "http://localhost:52670/Service1.svc/PostFile"
    oRequest.setRequestHeader "Content-Type", "vnd.ms-excel"
    oRequest.Send objStream.Read

    objStream.Close
    Set objStream = Nothing
    Set oRequest = Nothing
End Sub
Community
  • 1
  • 1
Jorgman
  • 21
  • 4
  • If you are needing to perform a file upload (i.e. a multipart mime type) its not so simple, see https://stackoverflow.com/questions/10954293/how-to-send-files-via-http-post-with-excel-using-vba – Alex K. Jun 05 '17 at 13:42
  • Thank you for your reply @AlexK. I have decided to go at this another way due to the complexity. – Jorgman Jun 05 '17 at 14:52

0 Answers0