Solved

Need Help Interpreting responseText Message from XMLHTTP Object

Posted on 2013-01-22
16
1,038 Views
Last Modified: 2013-01-23
Hello,

I am running ASP Classic on a Win 2008 R2 server.

I have code as follows:

Set xml = Server.CreateObject("Microsoft.XMLHTTP") url="http://www.myvendor.com/subfolder1/subfolder2/pagename.php?"
url=url & params
xml.Open "GET",url,False
xml.Send
calltext=xml.responseText
Set xml = Nothing

In the above, params is a conventional querystring (e.g., aaa=111&bbb=222&ccc=333).

calltext, which contains the AJAX responseText, contains the correct response information when printed into a web page or system generated email.

But I cannot perform any logic on calltext.  For example, if calltext contains "SUCCESS" as printed out on a web page or automated email, and I try logic like:

<%if calltext="SUCCESS" then
    'success logic
else
    'failure logic
end if%>

the failure logic gets executed.

I contacted the vendor (the owner of the system I am making the AJAX call to), and they confirmed that they are not performing any conversions of the responseText from ASCII to another encoding scheme.

Does anyone have any ideas?  Maybe the responseText property of the XMLHTTP object is not natively in string format, and I need to perform some kind of conversion before ASP Classic can interpret responseText correctly.

Thanks very much,
Stu Engelman
0
Comment
Question by:stuengelman
  • 9
  • 7
16 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38807477
Stu,
Do you know what the actual response is?

what happens if you do a

<%response.write calltext%>

Let's see the type of response.  Is it text, html, json, xml....
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38807489
You may have to parse through the json or xml is whats I am getting at.  If it is just text, try  if

if trim(calltext)="SUCCESS" then

or
if instr(1,trim(calltext), "SUCCESS",1)>0 then
  'your good
  else
  'no way
end if
0
 

Author Comment

by:stuengelman
ID: 38807854
Hi Padas,

I've tried cstr(calltext) and trim(cstr(calltext)), both to no avail in the ASP if/then logic.

<%response.write calltext%> results in normal ASCII (the correct, expected readable text with ASCII hex encoding).

Stu
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38807974
What is the exact  text you get when you response.write calltext? Please run this and view source and copy and paste from viewing source, not the what you see in your browser.  

I doubt you are getting simply, "SUCCESS".  Or maybe that is just what you see in the browser but it is really wrapped in json or xml which needs to be parsed.

fyi, cstr is for converting to text.  So if you are expecting text, no need to use cstr.  I used trim to remove white space to the left and right so " SUCCESS " becomes "SUCCESS".  I used instr, not cstr in order to search if the string exists.
0
 

Author Comment

by:stuengelman
ID: 38808490
Hi Padas,

response.write calltext results in the exact text "TEST_SUCCESS" (without the quotes).  This is the value I am testing against this in my code (not "SUCCESS" as in my sample code mentioned earlier).

I'll try your syntax (if instr(1,trim(calltext), "TEST_SUCCESS",1)>0 then) to see if that works.

"TEST_SUCCESS" is the successful responseText for my vendor's debug mode operation (i.e., the querystring format is tested for syntax accuracy, but no data is posted to their system).  When you go into live mode, the successful responseText is "SUCCESS".  A concern I have is that if any failure responseText values contain "SUCCESS", such as "NOT SUCCESSFUL - INVALID USERNAME", your method will invoke my success logic.  Is there any test I can use to determine the precise responseText?

Stu
0
 

Author Comment

by:stuengelman
ID: 38808506
Hi Padas,

I tried the syntax: if instr(1,trim(calltext),"TEST_SUCCESS",1)>0 then

The failure logic executed, even though "TEST_SUCCESS" was certain to be the result (I didn't change my querystring).

It appears this syntax does not solve the problem.

Stu
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38808529
I'm going to ask for the 3rd time....!!  VIEW THE SOURCE after you get the response  ;)
You are probably not getting straight text as output.  My guess is you are getting xml and we need to  parse the xml.   When you view source - pelase copy and paste the response.  Or better yet, can you point a link to the web service you are using so we can see what the response is supposed to be.

<%
Set xml = Server.CreateObject("Microsoft.XMLHTTP") url="http://www.myvendor.com/subfolder1/subfolder2/pagename.php?"
url=url & params
xml.Open "GET",url,False
xml.Send
calltext=xml.responseText
Set xml = Nothing
' PUT CODE TO READ THE XML RESPONSE HERE
  'http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_27800798.html

  'read xml node for response
  'theResponse=what_is_in_the_xml_node

MODE="Test"  'Test or Live
if MODE="Live" then
   if theResponse="SUCESS" then
       ' do stuff
   end if

else

    if theResponse="TEST_SUCCESS" then
        'do some test stuff
    end if

end if
%>

Open in new window

0
 

Author Comment

by:stuengelman
ID: 38808537
Hi Padas,

Forget my last post; I forgot to upload the code after changing it.  Your syntax does in fact solve the problem.  I'm certain the responseText is not in XML format (no parsing is necessary) as I've printed it out using response.write and it just says "TEST_SUCCESS" (without the quotes) without any XML structure tags.

But I still have the issue I mentioned earlier: if any failure responseText values contain "SUCCESS", such as "NOT SUCCESSFUL - INVALID USERNAME", your method will invoke my success logic.  Is there any test I can use to determine the precise responseText?

Thank you, Stu
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38808549
as I've printed it out using response.write and it just says "TEST_SUCCESS" (without the quotes) without any XML structure tags.
Did you view the source?  XML written inside of xml will not look like xml in the browser.  You have to view the source.  The actual response might be <response>SUCCESS</response> but you can't see the tags.  Actually, the response would be larger then that but you just see, SUCCESS.   This would be the reason you can't use if calltext="SUCCESS" then but you can use if instr(1,trim(calltext), "SUCCESS",1)>0 then

if you don't want to parse the xml you could do

dim ok
ok=0
if instr(1,trim(calltext), "SUCCESS",1)>0  then ' possible
   if instr(1,trim(calltext), "NOT SUCCESSFUL",1)=0 then ' yes
       ok=1
   end if
end if
if ok=1 then
   'do stuff because your happy it went through
   else
   'do something else because you need to say something
end if
0
 

Author Comment

by:stuengelman
ID: 38808565
Hi Padas,

I follow what you're saying.  I sent an email to the vendor asking whether the word SUCCESS appears in any failure values.  If not, I am all set.  Otherwise, I can check for "false positives" using your technique by getting a list of all operant exceptions from the vendor.

Thanks so much - great job!

Stu
0
 

Author Closing Comment

by:stuengelman
ID: 38808567
Excellent job.  Simple solution and fully solved problem.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38808590
Awesome!  

I'm still curious if you are getting an xml response as you have, "calltext=xml.responseText"
0
 

Author Comment

by:stuengelman
ID: 38808659
Hi Padas,

I don't know whether the responseXML property is being populated by the vendor.  I am using the responseText property in my code as I am certain they are populating that.

As mentioned earlier, I did print calltext to both a web page and an automated email, and it displayed without XML tags.  I also copy/pasted the web page output into an ASCII-to-hex converter, and it had exactly the same hex as hand-typed "TEST-SUCCESS".  It's possible that response.write(calltext) might strip any XML tags out in web output, but I doubt placing calltext in an email body would do this.  My best guess at this point is that xml.responseText has unprintable and invalid ASCII hex at the start or end.

At any rate, the vendor confirmed that no failure return values contain SUCCESS embedded anywhere.  So I don't have to code for any "false positive" exceptions.

I just switched from debug to live mode, and am waiting for the vendor to send me a screen shot so I can tell whether or not they captured all my querystring values correctly.  I'll shoot you another message to let you know how this went.

Thanks so much for all your great help.

Stu
0
 

Author Comment

by:stuengelman
ID: 38808669
Padas,

Live test lead posted perfectly to the vendor system.

We're set to do business!!

Stu
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38808703
It's possible that response.write(calltext) might strip any XML tags out in web output
No.  However, as I have said, when the response comes back as xml which it probably does and you do a response.write of that xml inside of the browser where you have the doctype set as html and it is inside of other <html> tags, you will not see xml in the browser. It will look like plain text. However, if you VIEW SOURCE you will probably see output like  below.  If you place this code inside of your html you will just see

Hello World!  ERROR  S0015  R0006

But viewing the browser source you see

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <soap:Envelope xmlns:soap="…">
      <soap:Body>
        <sms:sms xmlns:sms="hellip;">
          <sms:sentsms>
            <sms:phone>0821234567</sms:phone>
            <sms:message>Hello World!</sms:message>
            <sms:status>ERROR</sms:status>
            <sms:id>S0015</sms:id>
          </sms:sentsms>
          <sms:newsms>R0006</sms:newsms>
        </sms:sms>
      </soap:Body>
    </soap:Envelope>

Open in new window


What your code is doing with instr is looking throw all the xml for "Success" when you could  just parse out the response.  

I could be wrong though.  

I'm glad you have this working.
0
 

Author Comment

by:stuengelman
ID: 38811701
Hi Padas,

I did view the source code in MSIE after performing response.write(calltext), and all it had was TEST_SUCCESS.  Since I verified that the ASCII hex was correct, my best guess at this point is that invalid hex precedes or follows the responseText from the AJAX object.

Thanks again, Stu
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now