Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HttpWebRequest, "The browser does not support frames"

Posted on 2011-03-06
7
Medium Priority
?
1,918 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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

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

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…
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 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 PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

722 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