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. Read a Webpage content.

Read a Webpage content.

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 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.
  • A Offline
    A Offline
    AksharRoop
    wrote on last edited by
    #1

    I am writing an application that will give me content of a web page. I wrote following code for that. WebRequest objRequest = HttpWebRequest.Create("url"); StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream()); string result = sr.ReadToEnd(); sr.Close(); This works fine if the url i am connecting to does not require to login. I want to read content of a web page which requires first to put in login details (user/password) to get access. for that i tried with WebRequest objRequest = HttpWebRequest.Create("url"); NetworkCredential netCred = new NetworkCredential("User","Password"); objRequest.Credentials = netCred; StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream()); string result = sr.ReadToEnd(); sr.Close(); No success with this as well. It gets the contents of log in page and not the one specified by url. Can anyone help me with this? How to Read contents of a webpage which requires to login first. Thanks, AksharRoop

    C 1 Reply Last reply
    0
    • A AksharRoop

      I am writing an application that will give me content of a web page. I wrote following code for that. WebRequest objRequest = HttpWebRequest.Create("url"); StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream()); string result = sr.ReadToEnd(); sr.Close(); This works fine if the url i am connecting to does not require to login. I want to read content of a web page which requires first to put in login details (user/password) to get access. for that i tried with WebRequest objRequest = HttpWebRequest.Create("url"); NetworkCredential netCred = new NetworkCredential("User","Password"); objRequest.Credentials = netCred; StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream()); string result = sr.ReadToEnd(); sr.Close(); No success with this as well. It gets the contents of log in page and not the one specified by url. Can anyone help me with this? How to Read contents of a webpage which requires to login first. Thanks, AksharRoop

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      AksharRoop wrote:

      I want to read content of a web page which requires first to put in login details

      Do you log in through a web page, or does your browser display a login dialog for you? If you use forms based login (i.e. through a web page) then you will have to find a way to replicate that as if the user was actually sitting at the browser.

      * Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay


      Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

      A 1 Reply Last reply
      0
      • C Colin Angus Mackay

        AksharRoop wrote:

        I want to read content of a web page which requires first to put in login details

        Do you log in through a web page, or does your browser display a login dialog for you? If you use forms based login (i.e. through a web page) then you will have to find a way to replicate that as if the user was actually sitting at the browser.

        * Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay


        Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

        A Offline
        A Offline
        AksharRoop
        wrote on last edited by
        #3

        I have already logged on to that site using web-browser. I am writing an automated application that will read the content of web page and send it across. for that i will be logging on to web-page through browser and at some particular time my application will be triggered to read and send data. I tried with the code posted but it did not work for me. I am using Mozilla browser. Is there any way to connect to the same session?

        C 1 Reply Last reply
        0
        • A AksharRoop

          I have already logged on to that site using web-browser. I am writing an automated application that will read the content of web page and send it across. for that i will be logging on to web-page through browser and at some particular time my application will be triggered to read and send data. I tried with the code posted but it did not work for me. I am using Mozilla browser. Is there any way to connect to the same session?

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          AksharRoop wrote:

          I have already logged on to that site using web-browser.

          I would imagine then that it stores a cookie with the session information. You would have to replicate the contents of that cookie and send it with your request in your application in order to get to the password protected areas.

          AksharRoop wrote:

          Is there any way to connect to the same session?

          Not that I know of. You would have to replicate the session (probably using the above)

          * Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay


          Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

          A 1 Reply Last reply
          0
          • C Colin Angus Mackay

            AksharRoop wrote:

            I have already logged on to that site using web-browser.

            I would imagine then that it stores a cookie with the session information. You would have to replicate the contents of that cookie and send it with your request in your application in order to get to the password protected areas.

            AksharRoop wrote:

            Is there any way to connect to the same session?

            Not that I know of. You would have to replicate the session (probably using the above)

            * Developer Day Scotland 2 - Free community conference * The Blog of Colin Angus Mackay


            Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

            A Offline
            A Offline
            AksharRoop
            wrote on last edited by
            #5

            I am new to C#. Could you please put code snippet?

            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