Solved

HttpWebRequest, "The browser does not support frames"

Posted on 2011-03-06
7
1,758 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, those are probably the ones you need :-)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 13

Author Comment

by:josgood
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

772 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

12 Experts available now in Live!

Get 1:1 Help Now