durick
asked on
Winnhttp request to upload XML file is now failing?
I copied this code (UploadXML) from VB Forums and have used it in a MS Access 2003 application for over two + years now. BUT suddenly it has stopped working possibly due to a MS update? It now longer uploads the XML file.
Function UploadXML(strformurl As String, strFileName As String, inputfile As String, Optional strUserName As String, Optional strPassword As String) As String
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
Dim WinHttpReq As WinHttp.WinHttpRequest
Dim strBody As String
Dim strFile As String
Dim aPostBody() As Byte
Dim bound As String
Dim boundSeparator As String
Dim boundFooter As String
bound = "AaB03x"
boundSeparator = "--" & bound & vbCrLf
boundFooter = "--" & bound & "--" & vbCrLf
Set WinHttpReq = New WinHttpRequest
WinHttpReq.Open "POST", strformurl, False
If strUserName <> "" And strPassword <> "" Then
WinHttpReq.SetCredentials strUserName, strPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
End If
WinHttpReq.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & bound
strBody = boundSeparator
strBody = strBody & "Content-Disposition: form-data; name=""" & "login" & """" & vbCrLf & vbCrLf & strUserName
strBody = strBody & vbCrLf & boundSeparator
strBody = strBody & "Content-Disposition: form-data; name=""" & "pass" & """" & vbCrLf & vbCrLf & strPassword
strBody = strBody & vbCrLf & boundSeparator
strFile = getFile(strFileName)
strFileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName, "\"))
' strBody = strBody & "Content-Disposition: form-data; name=""" & "userfile" & """; filename=""" & strFileName & """" & vbCrLf & _
strBody = strBody & "Content-Disposition: form-data; name=""" & inputfile & """; filename=""" & strFileName & """" & vbCrLf & _
"Content-Type: text/xml" & vbCrLf & vbCrLf & strFile & vbCrLf
strBody = strBody & boundFooter
'convert to byte array
aPostBody = StrConv(strBody, vbFromUnicode)
WinHttpReq.send aPostBody
' WinHttpReq.send strBody
Do Until WinHttpReq.Status = 200
DoEvents
Loop
UploadXML = WinHttpReq.responseText
Set WinHttpReq = Nothing
End Function
Function getFile(strFileName As String) As String
Dim strFile As String
Dim nFile
' Grap the file
nFile = FreeFile
Open strFileName For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile
getFile = strFile
End Function
part of code in command1
uploadxml.txt
ASKER
I am using HTTPS
MSXML2.XMLHTTP did not fix the issue.
Can you access the page you upload to with internet explorer?XML2.XMLHTTP = Yes
MSXML2.XMLHTTP did not fix the issue.
Can you access the page you upload to with internet explorer?XML2.XMLHTTP = Yes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
WILL TRY thanks
ASKER
will try
If the second, then probably the set of ciphers does not match anymore between the client and the server.
Can you access the page you upload to with internet explorer?
Try to use MSXML2.XMLHTTP object instead of WinHttp.WinHttpRequest
That uses different windows API (WinInet) with different set of ciphers (same as IE uses).