Import Address Book from indiatimes.com in c#

jindal82 - May 15, 2008 - 11:45

Hello friends,

i am working on a task that "Import Address Book from indiatimes.com in c#."

in this module, i solved the login process, but i cannot get the contact.csv file.

can u tell me

here is my code

string strLoginUrl = "http://integra.indiatimes.com/Times/Logon.aspx?ru=" + HttpContext.Current.Server.UrlEncode("http://infinite.indiatimes.com/cgi-bin/gateway") + "&IS=058f3c27-6793-41c7-a676-81e3f3594a5c&NS=email&HS=kSVLJ96CWWzEmTwPZa1LD6YR7NM=";
string strLoginUrlPost = "op=login&login=" + strUserid + "&passwd=" + strPassword + "&rememberme=&rememberPwd=&Sign+In=";
HttpWebRequest webReqLogin = (HttpWebRequest)WebRequest.Create(strLoginUrl);
webReqLogin.Method = Utility.Post;
webReqLogin.UserAgent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
webReqLogin.KeepAlive = true;
webReqLogin.AllowAutoRedirect = false;
webReqLogin.UseDefaultCredentials = true;
webReqLogin.CookieContainer = new CookieContainer();
webReqLogin.ContentLength = strLoginUrlPost.Length;
webReqLogin.ContentType="application/x-www-form-urlencoded";

StreamWriter sw = new StreamWriter(webReqLogin.GetRequestStream(), System.Text.Encoding.ASCII);
sw.Write(strLoginUrlPost); sw.Close();
HttpWebResponse webResLogin = (HttpWebResponse)webReqLogin.GetResponse();

webResLogin.Cookies = webReqLogin.CookieContainer.GetCookies(webReqLogin.RequestUri);

//string strNewResponseUrl = webResLogin.StatusDescription;

StreamReader sr = new StreamReader(webReqLogin.GetResponse().GetResponseStream());
String strMainPage = sr.ReadToEnd();
sr.Close();

CookieCollection ccWebReqLogin = new CookieCollection();
ccWebReqLogin.Add(webResLogin.Cookies);
//webResLogin.Close();
//webReqLogin.Abort();

string strAddressBookRequestUrl = webResLogin.ResponseUri.ToString();
string strAddressBookRefererUrl = "http://tilmb19.indiatimes.com/h/search?st=contact";
//2========================================================================================
HttpWebRequest webReqAddress = (HttpWebRequest)WebRequest.Create(strAddressBookRequestUrl);

webReqAddress.Method = Utility.Get;
webReqAddress.UserAgent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
webReqAddress.Referer = webResLogin.ResponseUri.ToString();
webReqAddress.CookieContainer = new CookieContainer();
webReqAddress.CookieContainer.Add(ccWebReqLogin);

HttpWebResponse webResAddress = (HttpWebResponse)webReqAddress.GetResponse();
webResAddress.Cookies = webReqAddress.CookieContainer.GetCookies(webReqAddress.RequestUri);

StreamReader sr2 = new StreamReader(webResAddress.GetResponseStream());
string strAddressXml = sr2.ReadToEnd();
if (strAddressXml == string.Empty)
{
boolIsOK = false;
strError = Utility.ApplicationError;
return;
}
sr2.Close();
//webResAddress.Close();
//webReqAddress.Abort();

CookieCollection ccWebReqLogin2 = new CookieCollection();
ccWebReqLogin2.Add(webResAddress.Cookies);

strAddressBookRequestUrl = "http://tilmb19.indiatimes.com";
strAddressBookRefererUrl = "http://tilmb19.indiatimes.com/h/search?st=contact";
//2========================================================================================
HttpWebRequest webReqAddress2 = (HttpWebRequest)WebRequest.Create(strAddressBookRequestUrl);

webReqAddress2.UserAgent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
webReqAddress2.Referer = webResAddress.ResponseUri.ToString();
webReqAddress2.CookieContainer = new CookieContainer();
webReqAddress2.ContentType = "application/x-www-form-urlencoded";

webReqAddress2.CookieContainer.Add(ccWebReqLogin);
webReqAddress2.CookieContainer.Add(ccWebReqLogin2);

webReqAddress2.AllowAutoRedirect = true;

StreamReader sr21 = new StreamReader(webReqAddress2.GetResponse().GetResponseStream());
strAddressXml = sr21.ReadToEnd();
if (strAddressXml == string.Empty)
{
boolIsOK = false;
strError = Utility.ApplicationError;
return;
}
sr21.Close();
webReqAddress2.Abort();

Kamal Jindal
+91 999 110 1929

 
 

Drupal is a registered trademark of Dries Buytaert.