Check HTTP Status Code on AJAX Site

Ask general questions here.
tgagel
Posts: 33
Joined: Tue Jun 04, 2013 7:50 pm

Check HTTP Status Code on AJAX Site

Post by tgagel » Thu Aug 11, 2016 8:40 pm

The web application I am testing checks HTTP Status Codes on AJAX responses to determine if there is an error. Even when I know there should be an error (for example a 401 authorization error when no user is logged in) I am always getting a 200 OK response using the code (and many variations of the code) below.

Code: Select all

// Create the web request
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("https://www.ourUAT.com");
httpReq.AllowAutoRedirect = false;

// Get the response
HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();

// Report the results to ranorex report
Report.Info("httpReq = " + httpReq.ToString());
Report.Info("httpRes.StatusCode = " + httpRes.StatusCode.ToString());

// Close the response.
httpRes.Close();
I've seen other posts here about problems around waiting for AJAX calls to return and am wondering if this is a similar issue. As an example of what happens in the app, I've upload a picture showing the responses when trying to access the site without being logged in. The user is redirected to login page so there are some successful responses but what I am really interested in is the final 401 response.I suspect the response I am getting from the code is an initial success indicating that the site responded and it is not waiting for the AJAX calls to determine the true status.

Is there any way to get the final (or even all) status codes in the whole request stream? (I've tried some Streamreader code and that ended up giving me a single success response as well).

Any help or advice would be appreciated.

Todd
You do not have the required permissions to view the files attached to this post.

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: Check HTTP Status Code on AJAX Site

Post by Martin » Fri Aug 12, 2016 8:17 am

I can't say for sure due to my inexperience with HTTP statuses but doesn't the 401 actually reference only to the element that failed but not the whole page (or the part you are looking for)?

As I understand if the UAT will respond either to a not logged in user or a logged in user it will still be a successful response. If the site would not respond at all it would probably return an error status.

Further more if you don't actually allow auto redirect there will be no possible way for your code to actually reach the last lines of HTTP responses (if the code theoretically even handles this automatically). The redirect functionality is what will actually redirect the user to the "not logged in" part of the page after the initial visit to the site and the logged in check.

Did some testing of the code myself against google and I would suggest enableing the "AllowAutoRedirect" and see what it will return. In my case if it was set to false it returned "redirect" and when it was enabled it returned "OK".

Another thing to look at is how the responses and requests are actually read. (Should there be a "foreach" statement or "while" to go over the whole log etc).

I know my response is quite from one side to the other but I hope it will give you some ideas and a direction.

tgagel
Posts: 33
Joined: Tue Jun 04, 2013 7:50 pm

Re: Check HTTP Status Code on AJAX Site

Post by tgagel » Fri Aug 12, 2016 8:27 pm

I still couldn't get it to work but we have refocused and are going to check for HTML elements that indicate there was an error of some sort.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Check HTTP Status Code on AJAX Site

Post by Support Team » Wed Aug 17, 2016 12:51 pm

Hi tgagel,

There is already a feature request in our system which allows you to return the error code from a website.
If you want to raise the severity of this issue, may I ask you to send an email to [email protected] with a detailed description of your intention. Then we would be able to add you to this feature request.

I'm looking forward to your email.

Sincerely,
Matthias