I'm writing a code to bulk upload a set of xml files on a portal by using VBA HTTP POST. Sometimes when I'm getting the response after sending a file, the response comes like a web page instead of the normal xml file according to the portal specifications.
I've used the below code in order to do this and send the file to the portal; the portal requires digital certificate authentication. Normally, if the reply status is 200 then the response should be an xml file looking like this:
But sometimes the response look like this. It's like a logout web page, like my session is disconnected.
"Page logout function InsertActivexControl(clsid, params) { var container = document.getElementById("logoutActivexContainer"); if (navigator.appName == "Microsoft Internet Explorer") { var paramsCode = ""; for (var item in params) { paramsCode += ""; } container.innerHTML = ""
I have to mention that according to the portal specification, I have to send authentication credentials at each file upload. If I'm uploading 100 files, some 10% get this response.
URL = "https://webserviceapl.xxx/test/FCTEL/rest/upload?standard=CN&cif=" & cui & ""
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "POST", URL, False
Dim user As String
user = "CURRENT_USER\MY\" & nm & "" 'this is the certificate name
tk ="xyx123456789" 'this is the certificate token
'Set Content-Type header
http.setRequestHeader "Authorization", "Bearer " & tk
http.setOption 3, user
http.setRequestHeader "Content-Type", "application/xml"
'Send the form data To URL As POST binary request
http.send sFormData
http.waitForResponse 10000
Dim attempt As Integer
For attempt = 1 To 3
If http.Status = "200" Then GoTo GOOD
WaitMilliseconds (2000)
http.send sFormData
Next attempt
If http.Status <> "200" Then
errmsg = "Response error, http status = " & http.Status & " !"
Call LogMsg(errmsg)
errr = True
End If
GOOD:
strResp = http.responseText 'here I'm reading the response
As this is a synchronous call, initially I didn't use the waiting time and the retry loop. I introduced later, as I thought that maybe it's good wait more time for the response.
So please let me know what I should do in order to eliminate these strange responses. I'm not a qualified programmer so maybe I've done some beginner mistakes :)
Thank you all for your support !