I have an MS Access application that sends a unique identifier to a webpage, and the page is SUPPOSED to respond with First Name, Last Name, and DOB.
This recently broke, and my best trace at root cause is that the request is returning a blank body from the webpage, and our code uses the body to parse out the returned data. No body, no parsing.
There are NO errors as I step through the code. A coworker and I have a combined 3 days fighting with this. We've found the breaking points, but no leads on fixing it.
Here's an outline of what's supposed to happen, and details on where troubleshooting has led us:
On Click of "Lookup Button" on Access form, Validate ID Number Format
Dim sHTML as String
If ValidIDFormat(Me.ID.Value & "") Then
sHTML = GetDOCData(Me.ID.Value)
(I'll spare you the code behind "ValidIDFormat" as that's not the source of the issue)
GetDocData (above) is (I think?) the issue. GetDocData is a function that takes the ID Number and sends it as a request to the webpage as follows:
Public Function GetDOCData(aID As String) As String
Const SUB_NAME As String = "GetDOCData"
On Error GoTo ErrCond
Dim myurl As String
Dim t As Single
Dim TimedOut As Boolean
Dim Tries As Integer
Dim xHTTP As MSXML2.xmlhttp
Set xHTTP = New MSXML2.xmlhttp
myurl = "http://doclookup.com/GCA00P00/WIQ1/WINQ000" 'Upon inspecting the webpage, I found /GCA00P00/WIQ1/WINQ000 corresponds to the webpage's Form Method "Post" Action ( <form method="post" action="/GCA00P00/WIQ1/WINQ000"> )
TryAgain:
xHTTP.Open "POST", myurl, True
xHTTP.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
xHTTP.setRequestHeader "Accept-Encoding", "gzip, deflate"
xHTTP.setRequestHeader "Accept-Language", "en-US,en;q=0.9,ru;q=0.8"
xHTTP.setRequestHeader "Cache-Control", "max-age=0"
xHTTP.setRequestHeader "Content-Length", "213"
xHTTP.setRequestHeader "Host", "doclookup.com"
xHTTP.setRequestHeader "Origin", "http://doclookup.com"
xHTTP.setRequestHeader "Proxy-Connection", "keep-alive"
xHTTP.setRequestHeader "Referer", "http://doclookup.com/GCA00P00/WIQ1/WINQ000"
xHTTP.setRequestHeader "Upgrade-Insecure-Requests", "1"
xHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xHTTP.send "K01=WINQ000&DFH_STATE_TOKEN=&DFH_MAP_STATE_TOKEN=&M00_LAST_NAMEI=&M00_FIRST_NAMEI=&M00_MID_NAMEI=&M00_NAME_SUFXI=&M00_DOBCCYYI=&M00_ID_FLD1I=" & left(aID, 2) & "&M00_ID_FLD2I=" & Mid(aID, 3, 1) & "&M00_ID_FLD3I=" & Right(aID, 4) & "&M00_MISCID_FLD1I=&M00_MISCID_FLD2I="
t = Timer
Tries = 1
Do While (True)
DoEvents
If ((Timer - t) > 5) Then
TimedOut = True
xHTTP.abort
GetDOCData = ""
Exit Do
End If
If (xHTTP.ReadyState = 4) Then
If (xHTTP.Status <> 200) Then
If (Tries < 3) Then
Tries = Tries + 1
xHTTP.abort
GoTo TryAgain
Else
TimedOut = True
xHTTP.abort
GetDOCData = ""
Exit Do
End If
Else
TimedOut = False
GetDOCData = xHTTP.responseText
Debug.Print xHTTP.responseText
Exit Do
End If
End If
DoEvents
Loop
Set xHTTP = Nothing
Exit Function
ErrCond:
EventLogging AppSession.UserName, MSG_TYPE_ERROR, Err.Number, Err.Description, MOD_NAME & "." & SUB_NAME, AppSession.AppSilent
Set xHTTP = Nothing
End Function
Debug.Print output of the response:
<!DOCTYPE html>
<html><head>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta http-equiv="CacheControl" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="data:;base64,iVBORw0KGgo="/>
<script>
(function(){
window["bobcmn"] = "11111110101010200000005200000005200000001282ff3ca2200000096300000029application%2fx%2dwww%2dform%2durlencoded300000000300000006/TSPD/300000008TSPD_101300000004http3000000b008f09154e8ab2000c866a39c833f24d99d84e7901aac5a13c0c8ad737654afb25b96b27aba9f9b9008c421cc190a28006d5c954f4b5b362cf850d4f70b2a1ff8e8fcfb526acb91a5740a4c0e36f7d3e7e790a51f2ffbaf98300000107K01%3dWINQ000%26DFH_STATE_TOKEN%3d%26DFH_MAP_STATE_TOKEN%3d%26M00_LAST_NAMEI%3d%26M00_FIRST_NAMEI%3d%26M00_MID_NAMEI%3d%26M00_NAME_SUFXI%3d%26M00_DOBCCYYI%3d%26M00_ID_FLD1I%3d95%26M00_ID_FLD2I%3db%26M00_ID_FLD3I%3d1929%26M00_MISCID_FLD1I%3d%26M00_MISCID_FLD2I%3d200000000";
window.OYm=!!window.OYm;try{(function(){(function(){var S={decrypt:function(S){try{return JSON.parse(function(S){S=S.split("l");var I="";for(var l=0;l<S.length;++l)I+=String.fromCharCode(S[l]);return I}(S))}catch(l){}}};return S={configuration:S.decrypt("123l34l97l99l116l105l118l101l34l58l34l110l111l34l44l34l100l101l98l117l103l103l105l110l103l34l58l34l110l111l34l44l34l109l111l100l117l108l101l49l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l50l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l51l34l58l34l101l110l97l98l108l101l100l34l44l34l109l111l100l117l108l101l52l34l58l34l101l110l97l98l108l101l100l34l125")}})();
var iS=91;try{var JS,LS,OS=_(200)?0:1,ZS=_(567)?0:1,S_=_(300)?0:1;for(var __=(_(912),0);__<LS;++__)OS+=_(989)?1:2,ZS+=(_(404),2),S_+=(_(437),3);JS=OS+ZS+S_;window.jj===JS&&(window.jj=++JS)}catch(i_){window.jj=JS}var o_=!0;function J(S){var I=arguments.length,l=[];for(var Z=1;Z<I;++Z)l.push(arguments[Z]-S);return String.fromCharCode.apply(String,l)}
function z_(S){var I=69;!S||document[L(I,187,174,184,174,167,174,177,174,185,190,152,185,166,185,170)]&&document[J(I,187,174,184,174,167,174,177,174,185,190,152,185,166,185,170)]!==J(I,187,174,184,174,167,177,170)||(o_=!1);return o_}function L(S){var I=arguments.length,l=[],Z=1;while(Z<I)l[Z-1]=arguments[Z++]-S;return String.fromCharCode.apply(String,l)}function _i(){}z_(window[_i[O(1086763,iS)]]===_i);z_(typeof ie9rgb4!==O(1242178186108,iS));
z_(RegExp("\x3c")[O(1372114,iS)](function(){return"\x3c"})&!RegExp(O(42798,iS))[O(1372114,iS)](function(){return"'x3'+'d';"}));
var ii=window[L(iS,188,207,207,188,190,195,160,209,192,201,207)]||RegExp(J(iS,200,202,189,196,215,188,201,191,205,202,196,191),O(-73,iS))[O(1372114,iS)](window["\x6e\x61vi\x67a\x74\x6f\x72"]["\x75\x73e\x72A\x67\x65\x6et"]),ji=+new Date+(_(283)?392128:6E5),Ji,li,si,SI=window[J(iS,206,192,207,175,196,200,192,202,208,207)],iI=ii?_(896)?24437:3E4:_(789)?7473:6E3;
document[L(iS,188,191,191,160,209,192,201,207,167,196,206,207,192,201,192,205)]&&document[L(iS,188,191,191,160,209,192,201,207,167,196,206,207,192,201,192,205)](L(iS,209,196,206,196,189,196,199,196,207,212,190,195,188,201,194,192),function(S){var I=87;document[L(I,205,192,202,192,185,192,195,192,203,208,170,203,184,203,188)]&&(document[J(I,205,192,202,192,185,192,195,192,203,208,170,203,184,203,188)]===O(1058781896,I)&&S[J(I,192,202,171,201,204,202,203,188,187)]?si=!0:document[J(I,205,192,202,192,
185,192,195,192,203,208,170,203,184,203,188)]===L(I,205,192,202,192,185,195,188)&&(Ji=+new Date,si=!1,II()))});function II(){if(!document[J(33,146,150,134,147,154,116,134,141,134,132,149,144,147)])return!0;var S=+new Date;if(S>ji&&(_(848)?582451:6E5)>S-Ji)return z_(!1);var I=z_(li&&!si&&Ji+iI<S);Ji=S;li||(li=!0,SI(function(){li=!1},_(257)?0:1));return I}II();var jI=[_(425)?18598439:17795081,_(80)?2147483647:27611931586,_(166)?1983416588:1558153217];
function JI(S){var I=35;S=typeof S===O(1743045641,I)?S:S[J(I,151,146,118,151,149,140,145,138)](_(696)?24:36);var l=window[S];if(!l[L(I,151,146,118,151,149,140,145,138)])return;var Z=""+l;window[S]=function(S,I){li=!1;return l(S,I)};window[S][J(I,151,146,118,151,149,140,145,138)]=function(){return Z}}for(var LI=(_(728),0);LI<jI[L(iS,199,192,201,194,207,195)];++LI)JI(jI[LI]);z_(!1!==window[J(iS,170,180,200)]);window.IJ={Ll:"08d706d6c9018000e5822dadf90337bb593587216c9ab6a9c485b83578c4437a79e29efc9f34e830ff2af64ab8efa8fb630e6dd1e0826eb0daddd2bd5edfb2a1b1e82309950dfc445dbcd7cec14c66aad4477867c752f7bbeff0a97475a6bb1261632c2feef07f430cba4664d7e896295e4276a6c7e8e1303b350f2e5189a8f59b760816d0b62a13"};function O(S,I){S+=I;return S.toString(36)}
function oI(S){var I=+new Date,l;!document[J(46,159,163,147,160,167,129,147,154,147,145,162,157,160,111,154,154)]||I>ji&&(_(911)?801408:6E5)>I-Ji?l=z_(!1):(l=z_(li&&!si&&Ji+iI<I),Ji=I,li||(li=!0,SI(function(){li=!1},_(609)?0:1)));return!(arguments[S]^l)}function _(S){return 55>S}(function zI(I){I&&"number"!==typeof I||("number"!==typeof I&&(I=1E3),I=Math.max(I,1),setInterval(function(){zI(I-10)},I))})(!0);})();}catch(x){}finally{ie9rgb4=void(0);};function ie9rgb4(a,b){return a>>b>>0};
})();
</script>
<script type="text/javascript" src="/TSPD/08f09154e8ab20002596bec38bbab41a56da7004c2247af39c737e1fdd1f8257d17ddc6579566094?type=10"></script>
<noscript>Please enable JavaScript to view the page content.<br/>Your support ID is: 1436304770756522234.</noscript>
</head><body>
</body></html>
We noticed there is NOTHING returned between the "body" tags in the last 2 lines above ...
I also note the "Please enable JavaScript..." message, before the empty tags. However, if this is the root issue, I'm unaware of how to enable JS in VBA. I tried researching this, and couldn't find anything helpful.
Between #2 and #3 is where the disconnect occurs:
Take webpage response (above) and check if ID that was entered in Access correlates to 1, or multiple records for this person - housed in this website.
If (IsSingleID(sHTML)) Then ' "sHTML" here is the returned string from the webpage response in "GetDocData" Function above
Person = ParseDOCRecord(Me.ID.Value, sHTML)
'sometimes there are multiple returned values - housed in the website - for the person in question. One person can have multiple records, each given a unique ID. There's a different section of code, and different parsing, if multiple records/multiple IDs are returned.
IsSingleID is a Function defined as follows
Public Function IsSingleID(aHTML As String) As Boolean
Const SUB_NAME As String = "IsSingleID"
On Error GoTo ErrCond
Dim doc As New MSHTML.HTMLDocument
Dim o As Variant
IsSingleID = False
doc.Body.innerHTML = aHTML
For Each o In doc.getElementsByTagName("h2")
If (Trim(o.innerText) = "Person Information") Then
IsSingleID = True
Exit For
End If
Next
Set doc = Nothing
Exit Function
ErrCond:
EventLogging AppSession.UserName, MSG_TYPE_ERROR, Err.Number, Err.Description, MOD_NAME & "." & SUB_NAME, AppSession.AppSilent
End Function
The code EXITS here! There is no "o" in in doc.getElementsByTagName("h2")
Could this be because " doc.Body.innerHTML = aHTML " returns a Blank body?
I tried adding a watch to "aHTML" variable to confirm what part(s) of the webpage response (sHTML) is/are sent to "aHTML" variable in above function. But the variable/response was too long for the Watch window.
Regardless, the run never reaches the "ParseDOCRecord" Function in:
If (IsSingleID(sHTML)) Then
Person = ParseDOCRecord(Me.ID.Value, sHTML)
The run EXITS "IsSingleID" function, returns to "Lookup Button" Function (#1), and drops to a 'catch all' kind of message box, hard coded to return:
MsgBox "Unable to get information from DOC site."
I'm scratching my head on this.
Troubleshooting steps we've tried:
We tried updating references to Microsoft XML,v6.0 and using MSXML2.XMLHTTP60 instead. My reasoning was maybe there was a change to the older library that was picked up in the latest version.
Tried removing "/GCA00P00/WIQ1/WINQ000" from the URL, and simply using "doclookup.com"
Tried replacing "h2" tag with "form" tag, in doc.getElementsByTagName("h2") because I noticed I didn't see an "h2" tag in the inspected webpage
Here is the code from Form section of the webpage:
<form method="post" action="/GCA00P00/WIQ1/WINQ000">
<div class="border">
<input type="hidden" name="K01" value="WINQ000">
<input type="hidden" name="DFH_STATE_TOKEN" value="adyqlisv">
<input type="hidden" name="DFH_MAP_STATE_TOKEN" value="">
<div class="pair">
<label for="M00_LAST_NAMEI">Last Name:</label>
<input type="text" size="18" maxlength="18" name="M00_LAST_NAMEI" value="" id="M00_LAST_NAMEI">
</div>
<div class="pair">
<label for="M00_FIRST_NAMEI">First Name:</label>
<input type="text" size="11" maxlength="11" name="M00_FIRST_NAMEI" value="" id="M00_FIRST_NAMEI">
</div>
<div class="pair">
<label for="M00_MID_NAMEI">Middle Init:</label>
<input type="text" size="1" maxlength="1" name="M00_MID_NAMEI" value="" id="M00_MID_NAMEI">
</div>
<div class="pair">
<label for="M00_NAME_SUFXI">Name Suffix:</label>
<input type="text" size="3" maxlength="3" name="M00_NAME_SUFXI" value="" id="M00_NAME_SUFXI"> (SR, JR, etc.)
</div>
<div class="pair">
<label for="M00_DOBCCYYI">Birth Year:</label>
<input type="text" size="4" maxlength="4" name="M00_DOBCCYYI" value="" id="M00_DOBCCYYI"> (Optional, see above)
</div>
<div class="pair">
<label for="M00_DIN_FLD1I">DIN:<span class="hide"> Two digit number
</span></label>
<input type="text" size="2" maxlength="2" name="M00_ID_FLD1I" value="" id="M00_DIN_FLD1I" onfocus="select()" onkeyup="KeyPress(this,event,2,'WINQM00.form.M00_DIN_FLD2I.focus()')">
-
<label for="M00_DIN_FLD2I" class="hide">One character alpha</label>
<input type="text" size="1" maxlength="1" name="M00_ID_FLD2I" value="" id="M00_DIN_FLD2I" onfocus="select()" onkeyup="KeyPress(this,event,1,'WINQM00.form.M00_DIN_FLD3I.focus()')">
-
<label for="M00_DIN_FLD3I" class="hide">Four digit number</label>
<input type="text" size="4" maxlength="4" name="M00_ID_FLD3I" value="" id="M00_DIN_FLD3I" onfocus="select()">
(ID Number, format 99-A-9999, example 95-A-9876)
</div>
<div class="pair">
<label for="M00_NYSID_FLD1I">NYSID:<span class="hide"> Eight digit
number</span></label>
<input type="text" size="8" maxlength="8" name="M00_MISCID_FLD1I" value="" id="M00_MISCID_FLD1I" onfocus="select()" onkeyup="KeyPress(this,event,8,'WINQM00.form.M00_MISCID_FLD2I.focus()')">
-
<label for="M00_MISCID_FLD2I" class="hide">One character alpha</label>
<input type="text" size="1" maxlength="1" name="M00_MISCID_FLD2I" value="" id="M00_MISCID_FLD2I" onfocus="select()">
(For InterDepartmental Use Only; MISC ID Number)
</div>
<div class="aligncenter ">
<input type="submit" value="Submit">
<input type="button" onclick="javascript: location.href = location.href;" value="Reset">
</div>
</div>
</form>
What am I missing?
I hope I've explained this with the right amount of detail...
How can I get this request to return data again?
Follow up based on comments/comment threads below...
I did a search for a record on the website (not one within the application) in order to generate response log from Network tab of webpage. DIN # 18B3079 screenshot of response as follows: