C# http request cookies or redirect error -


i trying use c# code log site. has been working can't work , can't figured out did website changed cookie setting or redirect method wrong: here code. source of this.sitepage "www.pof.com" , this.loginurl "processlogin.aspx"

   private void loginaction()         {             this.m_username = this.users[rotationcount];             this.m_password = this.passwords[rotationcount];             this.getcookies();             connectionsuccessful = this.login();         }      private boolean login()     {         boolean connected = false;         string postdata = string.format("username={0}&password={1}", m_username, m_password);         htmlagilitypack.htmldocument htmldoc = this.getpage(this.sitepage + "/" + this.loginurl, postdata);         htmlnodecollection linknodes = htmldoc.documentnode.selectnodes("//a[@href]");         foreach (htmlnode linknode in linknodes)         {             htmlattribute link = linknode.attributes["href"];             switch (link.value)             {                 case "basicsearch.aspx":                     this.searchurl = link.value;                     break;                 case "inbox.aspx":                     this.inboxurl = link.value;                     break;                 default:                     if(link.value.startswith("whoviewedme.aspx"))                         connected = true;                     break;             }         }         return connected;     }      private htmlagilitypack.htmldocument getpage(string url, string postdata)     {         try         {             stream datastream;             httpwebrequest request = (httpwebrequest)webrequest.create(url);             request.cookiecontainer = new cookiecontainer();             request.cookiecontainer.add(cookies);             request.allowautoredirect = true;             request.useragent = "mozilla/5.0 (windows nt 6.1) applewebkit/535.2 (khtml, gecko) chrome/15.0.874.121 safari/535.2";             request.contenttype = "application/x-www-form-urlencoded";              if (postdata != null)             {                 request.method = "post";                 byte[] bytearray = encoding.utf8.getbytes(postdata);                 request.contentlength = bytearray.length;                 datastream = request.getrequeststream();                 datastream.write(bytearray, 0, bytearray.length);                 datastream.close();             }              httpwebresponse response = (httpwebresponse)request.getresponse();             datastream = response.getresponsestream();             string sourcecode = "";             using (streamreader reader = new streamreader(datastream))             {                 sourcecode = reader.readtoend();             }              htmlagilitypack.htmldocument htmldoc = new htmlagilitypack.htmldocument();             htmldoc.loadhtml(sourcecode);             this.cookies.add(response.cookies);             return htmldoc;         }         catch (exception)         {             return null;         }     }      private void getcookies()     {         try         {             //first request cookies             cookies = new cookiecollection();             httpwebrequest request = (httpwebrequest)webrequest.create(this.sitepage);             request.cookiecontainer = new cookiecontainer();             request.cookiecontainer.add(cookies);              //get response server , save cookies first request..             httpwebresponse response = (httpwebresponse)request.getresponse();             cookies = response.cookies;         }         catch (exception)         {         }     } 

the code fails @ part "foreach (htmlnode linknode in linknodes)" , when check htmldoc 2 lines above that, can't see in document node. appreciated >


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -