Hello, as requested, I'm trying to find a simple form that will upload a file to a server using a username and password. If I can hard code the specifics and click one button, that would be great. The current form i'm using works, however, when we set up the server to use credentials, we keep gettings erros. So i'm searching for a smipler way to accomplish this. I will include the current code.



Error that is coming from the form:

"The Server returned an invalid or unrecognized response."




Error coming from the server side is:


"Invalid method in request –-Xu02=$"





(I omitted username, password, and server location)

Code:
----------------------------FORM CODE-----------------------------------




Private Sub Command1_Click()

Dim iArray

'Set your filename to upload here
iArray = Array("C:\Documents and Settings\rdstephens\Desktop\Upload.txt")

'Set path to php upload script here
Text1.Text = UploadFiles(iArray, "--------------Server Address--------------", Text2.Text, "******", "******")

End Sub









----------------------------SCRIPT CODE------------------------------------



'You need reference to Microsoft WinHTTP Services 5.0 or 5.1 to use this example

'Credit to Joseph Z. Xu ()
'Modified by Mohd Idzuan Alias () August 18, 2004
'Modified by Kung Fu Panda, Wizard of Warcraft, and The Intern, June 19, 2008


Dim WinHttpReq As WinHttp.WinHttpRequest
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
Const BOUNDARY = "Xu02=$"
Const HEADER = "--Xu02=$"
Const FOOTER = "--Xu02=$--"


Function UploadFiles(strFileName As Variant, strURL As String, Optional postVar As  String, _ Optional strUserName As String, Optional strPassword As String) As String

Dim fname As String
Dim strFile As String
Dim strBody As String
Dim aPostBody() As Byte
Dim nFile As Integer

Set WinHttpReq = New WinHttpRequest

' Turn error trapping on
On Error GoTo SaveErrHandler

' Assemble an HTTP request.
strURL = strURL & "?slots=" & CStr(UBound(strFileName) + 1) & "&" & postVar
WinHttpReq.Open "POST", strURL, False
Debug.Print strURL

If strUserName <> "" And strPassword <> "" Then
' Set the user name and password.
WinHttpReq.SetCredentials strUserName, strPassword, _
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
End If

'-------------------------- Becareful not to mingle too much here -----------------------------------

' Set the header
WinHttpReq.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & BOUNDARY

' Assemble the body
strBody = HEADER                        ' Starting tag

For i = 0 To UBound(strFileName)

' Grap the name
fname = strFileName(i)

' Grap the file
strFile = getFile(fname)

strBody = strBody & vbCrLf & "Content-Disposition: form-data; name=""" & "name" & """; filename=""" & fname & """ " & vbCrLf & "Content-type: file" & _
vbCrLf & vbCrLf & strFile & vbCrLf

If i < UBound(strFileName) Then
strBody = strBody & "--Xu02=$" ' This is boundary tag between two files
End If
strFile = ""

Next i

strBody = strBody & FOOTER             ' Ending tag
'----------------------------------------------------------------------------------------------------

' Because of binary zeros, post body has to convert to byte array
aPostBody = StrConv(strBody, vbFromUnicode)

' Send the HTTP Request.
WinHttpReq.Send aPostBody

' Display the status code and response headers.
'UploadFiles = WinHttpReq.GetAllResponseHeaders & "  " & WinHttpReq.ResponseText
UploadFiles = WinHttpReq.ResponseText

Set WinHttpReq = Nothing

Exit Function

SaveErrHandler:
UploadFiles = Err.Description

Set WinHttpReq = Nothing

End Function
Function getFile(strFileName As String) As String

Dim strFile As String

' Grap the file
nFile = FreeFile
Open strFileName For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile

getFile = strFile

End Function