[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2001-09-14
10
Medium Priority
?
703 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

656 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