Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. get the stream writer of the webbrowser control

get the stream writer of the webbrowser control

Scheduled Pinned Locked Moved C#
question
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yustme
    wrote on last edited by
    #1

    Hi, How can I get the 'pointer' of the stream writer the webbrowser control uses to navigate to websites? Thanks in advance!

    K 1 Reply Last reply
    0
    • Y Yustme

      Hi, How can I get the 'pointer' of the stream writer the webbrowser control uses to navigate to websites? Thanks in advance!

      K Offline
      K Offline
      Kristian Sixhoj
      wrote on last edited by
      #2

      I *think* the DocumentStream[^] property is what you're looking for.

      :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

      Y 1 Reply Last reply
      0
      • K Kristian Sixhoj

        I *think* the DocumentStream[^] property is what you're looking for.

        :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

        Y Offline
        Y Offline
        Yustme
        wrote on last edited by
        #3

        I thought that's the one i needed too. But where would i put the url to navigate to another url with it?

        K 1 Reply Last reply
        0
        • Y Yustme

          I thought that's the one i needed too. But where would i put the url to navigate to another url with it?

          K Offline
          K Offline
          Kristian Sixhoj
          wrote on last edited by
          #4

          Yustme wrote:

          But where would i put the url to navigate to another url with it?

          I'm not sure if I understand this, but to navigate to another URL, you call the Navigate method of the webbrowser control, passing in the URL to navigate to, like so:

          webBrowser1.Navigate("http://codeproject.com");

          :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

          Y 1 Reply Last reply
          0
          • K Kristian Sixhoj

            Yustme wrote:

            But where would i put the url to navigate to another url with it?

            I'm not sure if I understand this, but to navigate to another URL, you call the Navigate method of the webbrowser control, passing in the URL to navigate to, like so:

            webBrowser1.Navigate("http://codeproject.com");

            :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

            Y Offline
            Y Offline
            Yustme
            wrote on last edited by
            #5

            Ideally would be using the response class. Its much faster. But i can't log in on a website with it. I got a multithreaded application. When entering the event: WebBrowserDocumentCompletedEventArgs , another thread already navigated to another page. So i'll lose the last page where the webcontrol navigated to. Making the threads sleep a few seconds, doesn't help either. All i'm trying to get is the page content in html format.

            K 1 Reply Last reply
            0
            • Y Yustme

              Ideally would be using the response class. Its much faster. But i can't log in on a website with it. I got a multithreaded application. When entering the event: WebBrowserDocumentCompletedEventArgs , another thread already navigated to another page. So i'll lose the last page where the webcontrol navigated to. Making the threads sleep a few seconds, doesn't help either. All i'm trying to get is the page content in html format.

              K Offline
              K Offline
              Kristian Sixhoj
              wrote on last edited by
              #6

              Yustme wrote:

              All i'm trying to get is the page content in html format.

              By that, do you mean getting the HTML behind the page? If so, the DocumentText[^] property is what you need. It also allows you to modify the HTML contents, but I'm not sure if it's gonna work with what you're trying to accomplish:

              Yustme wrote:

              But i can't log in on a website with it.

              You may wanna have a look at the HtmlDocument[^] class.

              :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

              Y 1 Reply Last reply
              0
              • K Kristian Sixhoj

                Yustme wrote:

                All i'm trying to get is the page content in html format.

                By that, do you mean getting the HTML behind the page? If so, the DocumentText[^] property is what you need. It also allows you to modify the HTML contents, but I'm not sure if it's gonna work with what you're trying to accomplish:

                Yustme wrote:

                But i can't log in on a website with it.

                You may wanna have a look at the HtmlDocument[^] class.

                :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

                Y Offline
                Y Offline
                Yustme
                wrote on last edited by
                #7

                Yes i can get the html code from the page. But i need to navigate to it first. And there are a lot of pages to walk through.

                K 1 Reply Last reply
                0
                • Y Yustme

                  Yes i can get the html code from the page. But i need to navigate to it first. And there are a lot of pages to walk through.

                  K Offline
                  K Offline
                  Kristian Sixhoj
                  wrote on last edited by
                  #8

                  What exactly are you trying to create? Perhaps the WebBrowser control isn't the ideal solution for this, but that depends on what you're trying to do.

                  :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

                  Y 1 Reply Last reply
                  0
                  • K Kristian Sixhoj

                    What exactly are you trying to create? Perhaps the WebBrowser control isn't the ideal solution for this, but that depends on what you're trying to do.

                    :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

                    Y Offline
                    Y Offline
                    Yustme
                    wrote on last edited by
                    #9

                    Getting html code of a topic in a vbulletin forum. If you're not logged in, you're not allowed to view the topic. I can't log in with the response class. This was my try:

                    private string login(string url, string username, string password)
                    {
                    string values = "vb_login_username={0}&vb_login_password={1}";
                    values += "&securitytoken=guest&cookieuser=checked&do=login";

                    		values = string.Format(values, username, password);
                    	
                    		HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                    
                    		req.Method = "POST";
                    		req.ContentType = "application/x-www-form-urlencoded";
                    		req.ContentLength = values.Length;
                    		req.Timeout = 10000;
                    
                    		CookieContainer a = new CookieContainer();
                    		req.CookieContainer = a;
                    
                    		System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error
                    
                    		using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
                    		{ writer.Write(values, 0, values.Length); }
                    
                    		this.response = (HttpWebResponse)req.GetResponse(); 
                    
                    		StringBuilder output = new StringBuilder();
                    
                    		foreach (var cookie in response.Cookies)
                    		{
                    				output.Append(cookie.ToString());
                    				output.Append(";");
                    		}
                    
                    		
                    	  return output.ToString();
                    
                    	}  
                    

                    </pre>

                    K 1 Reply Last reply
                    0
                    • Y Yustme

                      Getting html code of a topic in a vbulletin forum. If you're not logged in, you're not allowed to view the topic. I can't log in with the response class. This was my try:

                      private string login(string url, string username, string password)
                      {
                      string values = "vb_login_username={0}&vb_login_password={1}";
                      values += "&securitytoken=guest&cookieuser=checked&do=login";

                      		values = string.Format(values, username, password);
                      	
                      		HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                      
                      		req.Method = "POST";
                      		req.ContentType = "application/x-www-form-urlencoded";
                      		req.ContentLength = values.Length;
                      		req.Timeout = 10000;
                      
                      		CookieContainer a = new CookieContainer();
                      		req.CookieContainer = a;
                      
                      		System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error
                      
                      		using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
                      		{ writer.Write(values, 0, values.Length); }
                      
                      		this.response = (HttpWebResponse)req.GetResponse(); 
                      
                      		StringBuilder output = new StringBuilder();
                      
                      		foreach (var cookie in response.Cookies)
                      		{
                      				output.Append(cookie.ToString());
                      				output.Append(";");
                      		}
                      
                      		
                      	  return output.ToString();
                      
                      	}  
                      

                      </pre>

                      K Offline
                      K Offline
                      Kristian Sixhoj
                      wrote on last edited by
                      #10

                      I don't know why your login request doesn't work, but another approach to the problem could be: 1. Navigate to the URL using the WebBrowser control. 2. If a login form is displayed, use HtmlDocument to fill in the values (username + password) and "click" the Login button. Depending on how the site is coded, the browser should automatically navigate to the requested forum topic. 3. Grab the HTML by using the DocumentStream property. Although this definitely isn't the most ideal solution if you have to "visit" several sites. WebRequest is probably the way to go if that's the case. Have you got any idea as to why your login request fails? Does the site display an error message?

                      :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

                      Y 1 Reply Last reply
                      0
                      • K Kristian Sixhoj

                        I don't know why your login request doesn't work, but another approach to the problem could be: 1. Navigate to the URL using the WebBrowser control. 2. If a login form is displayed, use HtmlDocument to fill in the values (username + password) and "click" the Login button. Depending on how the site is coded, the browser should automatically navigate to the requested forum topic. 3. Grab the HTML by using the DocumentStream property. Although this definitely isn't the most ideal solution if you have to "visit" several sites. WebRequest is probably the way to go if that's the case. Have you got any idea as to why your login request fails? Does the site display an error message?

                        :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

                        Y Offline
                        Y Offline
                        Yustme
                        wrote on last edited by
                        #11

                        Im already filling the form's manually in the webbrowser control. My idea why the login fails is because of the 'salt' it adds after the password. And it gets the salt from the DB. If i could fill in the forms programmatically with webresponse and request, would be great. This way, i dont have to load anything, which takes a lot of time.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups