Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to use vba/XMLHTTP in an Access 2010 database to upload a file. While it is going through the process and I'm not receiving any errors, nothing ends up on my web site.

Here's the code which is called using:

response = 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
share|improve this question
    
most likely you need use objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" and provide actually what to send in objHttp.send(formData) msdn.microsoft.com/en-us/library/ie/hh772723(v=vs.85).aspx great places to start support.microsoft.com/kb/290591 –  Maksym Markov Jun 7 '13 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.