从VBA发布到REST的流

时间:2017-06-05 13:39:24

标签: vba excel-vba excel

我正在从excel文件创建一个流,需要将其发布到Web服务。当我尝试'MsgBox objStream.Size'它会给我完整的文件大小,但在我发布到我的服务并检查流的长度后,它是0.我是否正确发送了POST?

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

0 个答案:

没有答案