Solved

How do I get http status code from IE browser control?

Posted on 2001-09-14
10
648 Views
Last Modified: 2013-11-20
Hi,

I could not find any method or property which returns the HTTP status code in Internet Explorer control (IE 5.5).  Currently I am guessing the status code by checking the title of the page.

Any help will be greatly appreciated.

Thanks.
0
Comment
Question by:sgovinda
10 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6483752
what do you mean the 404 type response? the contents of the page is where it will be - the browser hides all inner workings and trnslates the status messages into a web page if it is an error.

If you need the raw status codes you will have to use the WinInet functions yourself - but that means you will have trouble rendering it
0
 
LVL 3

Expert Comment

by:cypherljk
ID: 6483785
I'm not real familiar with that control but is it possible to call the GetReadyState() function? Just a thought I couldn't find much documentation.

My 2 cents...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6484376
Specifically, what status are you trying to get?  And if you get it, what would you want to do with it?

In you OnDocumentComplete handler, you can get access to the IHTMLDocument2 interface and perhaps learn something by scraping the contents.  If nothing else, you can get the URL to see if it what you think it should be.

I don't see any clear way to get the actual HTTP status (eg, the 404 or 401 code).  One possibility would be to provide an OnBeforeNavigate2 handler.  Then use CHttpConnection/CHttpFile to pre-read the page and check for an error.  If all is OK, then pass it on to the normal handler.  But there could easily be a better way.

-- Dan
0
 
LVL 1

Expert Comment

by:MRNMurthy
ID: 6484607
Hi,

If u use the CHttpFile class then u will be able to get the status code from it is method QueryInfoStatusCode( DWORD& dwStatusCode ) to which u have to pass referrence of a DWORD. For the details u can go thru the MSDN even sample code is available in it.

From

MRN Murthy

0
 
LVL 1

Author Comment

by:sgovinda
ID: 6484730
Thanks for the response guys.

I am working on an application which automates the browser and extracts the content of a page.  To decide whether I have a valid page, http status code is a must.

Events like BeforeNavigate2, DocumentComplete etc is raised even for a failure condition.  Parsing the title or content of a page to find the http status code is unreliable.

I cannot use CHttpFile because in case of secure pages (for example SSL), I have to handle all the authentication in my code.  I am sure it is easier to let the browser do the job.

I still wonder why IE is hiding such a simple and important data like http status code. (considering the rich API it provides for parsing the page)


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 49

Expert Comment

by:DanRollins
ID: 6485132
>>I cannot use CHttpFile because in case of secure pages
>>(for example SSL), I have to handle all the athentication
>>in my code.  I am sure it is easier to let the browser do the job.

Given this, then I think you already know what is happeneing... the Webrbrowser control is doing exactly what you want it to do!  It is handling the 40x errors for you!

By the time you get control at OnDocumentComplete, there *is* no HTTP error code for you to process (it would always be 200, "no error")

So now to solve your problem....

You are writing code to automate walking HTML pages, so there is no reason to use a Webrowser control at all -- unless you need a UI for display-only functionality.  SO just drop-dwon to using CHTTPConnection and CHttpFile... but that leaves the problem of handling security such as HTTPS connections.

That turns out to be pretty easy....

After CHttpFile::SendRequest(), you can call pFile->QueryInfoStatusCode or QueryInfo to obtain error info.  When you get back HTTP_STATUS_DENIED, then you can programmatically handle it.  See:

http://msdn.microsoft.com/workshop/networking/wininet/overview/authentication.asp

Also, the "TEAR" sample on your MSDN disk shows most of what you need to do to grab pages without a web browser.  This link to MS seems to be broken, but it might start working later:

80% TEAR: "Tearing" HTML Pages Off the Internet  
http:// msdn.microsoft.com / library / en-us / vcsample98 / html / _sample_mfc_tear.asp  

http://msdn.microsoft.com/library/en-us/vcsample98/html/_sample_mfc_tear.asp

-==-=-=-=-=-

A reasonable compromise would be to use both methods -- a WebBrowser control in which you pre-access each URL in the OnBeforeNavigate2 handler.  You have rejected this suggestion previously, so I won't bother to show you any sample code, but if you change your mind, let me know.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6496298
hi sgovinda,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LVL 1

Author Comment

by:sgovinda
ID: 6496704
Hi Dan,

The solution you were suggesting doesn't fit my needs exactly. Also. it is quite an amount of work (my schedule doesn't permit it right now).  I would rather try your points at my own leisure.

I have committed to give points anyway.  I can as well give it you.  If you have few samples, you can post it, it would be helpful.

Thanks.


0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 6497678
Sorry sgovinda,
I have found it unprofitable to workout example code and otherwise spend time solving problems for persons who admit up front that they don't like the obvious solution.

-- Dan
0
 
LVL 1

Author Comment

by:sgovinda
ID: 6498058
Hi Dan,

I am giving you the points anyway.  If you don't have some samples ready at hand, I don't expect you to spend time on the problem.

Thanks to all the guys who responded to this question.
sgovinda.  
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

10 Experts available now in Live!

Get 1:1 Help Now