1

我正在尝试在 Access 2010 数据库中使用 vba/XMLHTTP 来上传文件。虽然它正在经历这个过程并且我没有收到任何错误,但我的网站上没有任何内容。

这是使用以下方法调用的代码:

响应 = HTTP_FileUpload(ShowName, "www.website_name","POST")

Public Function HTTP_FileUpload(FileName As String, ByVal pUrl As String, _
    Optional ByVal pMethod As String = "GET") As String
Dim strResponse As String

On Error GoTo ErrorHandler

Dim xmlStream As Object
Set xmlStream = CreateObject("ADODB.Stream")
xmlStream.Mode = 3 ' //read write
xmlStream.Type = adTypeBinary
xmlStream.Open
xmlStream.LoadFromFile FileName

Dim objHttp As Object
Set objHttp = CreateObject("MSXML2.XMLHTTP")
objHttp.Open pMethod, pUrl, False
Debug.Print "file Name is " & FileName & "   Size of file is " & xmlStream.Size

objHttp.setRequestHeader "Content-Type", "text/generic"
objHttp.setRequestHeader "Content-Length", xmlStream.Size
objHttp.send
strResponse = objHttp.responseText
HTTP_FileUpload = strResponse
Set objHttp = Nothing
Exit Function

ErrorHandler:
    MsgBox "Error - code is " & Err.Number & " - " & Err.Description

End Function
4

0 回答 0