Logging to Website
-
Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.
-
Can you please elaborate more on your question so that it is easier to answer it? What you are trying to download and from which site using csharp ? HTH
Jinal Desai - LIVE Experience is mother of sage....
Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??
-
Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.
you want the
HttpWebRequest
andHttpWebResponse
classes, and theCredentials
property. Use Google to get lots of examples. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??
Hi Naveen, you can study WebClient class. http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx
-
Hello All, I am very much new to C# ... I am trying to log in to website and download some information. is it possible to do that using C# ?? Please suggest me some ideas Thanking you, Naveen HS.
I have the same problem to login to a website, therefore i have only a half answer. I know 4 methods to download informations from a website. 1. System.NET.WebClient This is a native Client class to download Data or the html string from a internet adress.
WebClient webClient = new WebClient();
webClientData = webClient.DownloadData(uri);as far as i know it is possible to login to a website with this class, but i never have find out how. 2. System.Windows.Forms.WebBrowser This is a internet explorer class for the framework. You can login to a website, because it uses the variables/cookies/etc. from the internet explorer. 3. System.NET.WebRequest In this class it's possible to use POST and GET, this is needed to login to a website, but i don't know how to POST login informations, i only know how to donwload the data from a website.
byte[] buffer;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
System.IO.Stream s = resp.GetResponseStream();4. TCP Socket Yes, this protocol bases upon to TCP, you can connect to the website and communicate over the Hypertext Transfer Protocol with the website. If you need more informations about the methods, you can use google. I hope i could help you a bit and sorry for my bad english.
-
Hi Jinal Desai, Thanks for the response. consider some some website www.somesite.com , that has login id & password, once we login it takes to information page, i am trying to download the content from the information page. so can you please give some suggestions how to start with this work ??
Find following code useful for the same.
private void DownloadFile( string fname, bool forceDownload )
{
string path = MapPath( fname );
string name = Path.GetFileName( path );
string ext = Path.GetExtension( path );
string type = "";
// set known types based on file extension
if ( ext != null )
{
switch( ext.ToLower() )
{
case ".htm":
case ".html":
type = "text/HTML";
break;case ".txt": type = "text/plain"; break; case ".doc": case ".rtf": type = "Application/msword"; break; }
}
if ( forceDownload )
{
Response.AppendHeader( "content-disposition",
"attachment; filename=" + name );
}
if ( type != "" )
Response.ContentType = type;
Response.WriteFile( path );
Response.End();
}Also find following link useful... Downloading a File with a Save As Dialog in ASP.NET[^] HTH
Jinal Desai - LIVE Experience is mother of sage....