Read a Webpage content.
-
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
-
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
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.
-
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.
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?
-
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?
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.
-
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.
I am new to C#. Could you please put code snippet?