Solved

HttpWebRequest, "The browser does not support frames"

Posted on 2011-03-06
7
1,890 Views
Last Modified: 2012-05-11
Using .Net 4.0, I'm trying to read a page that apparently requires a browser that supports frames.  I'm not receiving the contents I expect -- the response includes "The browser does not support frames".

I've tried setting the HttpWebRequest UserAgent, as shown below (I tried the commented-out strings as well) -- to no avail.

Any ideas?

      private String GetPage(String url) {
         const String fireFoxUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15";
         //const String fireFox_3_6_3_UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729; .NET4.0E)";
         //const String IE_8_0_7600_UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MAAU; InfoPath.2; .NET CLR 1.1.4322; MS-RTC LM 8; .NET4.0C; .NET4.0E; OfficeLiveConnector.1.5; OfficeLivePatch.1.3)";
         //
         String result = String.Empty;
         try {
            Uri uri = new Uri(url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);   // This connects to the web page
            request.UserAgent = fireFoxUserAgent;                              // Otherwise "The browser does not support frames"
            HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // This receives the web page response
            using (StreamReader r = new StreamReader(response.GetResponseStream())) {
               result = r.ReadToEnd();                                     // Read the entire page description
            }
         } catch (System.Net.WebException we) {
            MessageBox.Show("GetPage: " + we.Message);
         } catch (Exception e) {
            MessageBox.Show("GetPage: " + e.Message);
         }
         return result;
      }
0
Comment
Question by:josgood
[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
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 35045855
Doesn't the result also include a iframe tag? You could get the url specified there.

Most of the times such a page contains javascript with an alternative text for non-frame supporting browsers.
0
 
LVL 13

Author Comment

by:josgood
ID: 35046515
The result contains <Frame>...</Frame> sections.  Do I need to fetch the SRC= tags?

I'm pretty noob at this.

Result attached.
temp.txt
0
 
LVL 10

Expert Comment

by:Jacco
ID: 35046651
Yes, those are probably the ones you need :-)
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 13

Author Comment

by:josgood
ID: 35046684
OK, I'll give that a shot.  I'm thinking that, for each SRC= tag, I'll append the tag to the URI for the page and fetch that.
0
 
LVL 13

Author Comment

by:josgood
ID: 35053383
I may not be able to get back to this for a few days...sorry about the delay.

I was able to fetch the form I wanted...at least when I load the returned data into Firefox it looks very similar to the form I want.  The form is ASP-generated, so looks different than what I'm used to seeing.

I need to learn quite a bit more about this.  I want to post some content to the form and then push a button.

My big barrier is I don't understand how to name the names of the "field=value" pairs that I want to post to the form.

:) Life would be less fun if there was nothing to learn! :)

I'll probably hit this again next weekend.
0
 
LVL 10

Accepted Solution

by:
Jacco earned 500 total points
ID: 35053825
Hi,

The frame is loaded through a GET request. If there is a form on it there will be a lot of INPUT tags inside the html. You need to get de ID/NAMEs from all of them inside the FORM tag you are interested in.

These are the fields. You can put values in them for your POST call. You need to put special values in __EVENT_TARGET and __VIEWSTATE. (Check with Fiddler what need to go inside __EVENT_TARGET when you push the button that posts the form, __VIEW_STATE needs the value that is already in the HTML code.

Later, Jacco
0
 
LVL 13

Author Comment

by:josgood
ID: 35132381
It looks to me as though you've given me enough data to solve this problem.  I've put this task aside to deal with more urgent ones.

I appreciate your help.

Thank you.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

636 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