Solved

HttpWebRequest, "The browser does not support frames"

Posted on 2011-03-06
7
1,860 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

738 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