Solved

HttpWebRequest, "The browser does not support frames"

Posted on 2011-03-06
7
1,777 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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.

919 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

13 Experts available now in Live!

Get 1:1 Help Now