title: I did an HTTPWebRequest to login, but after I try to access the data I get prompted to login again?
body: <p>Okay guys, I recently downlaoded LiveHTTPHeaders... I'm trying to make a code so I can login to this website : <a href="http://stproperty.sg" rel="nofollow">http://stproperty.sg</a>.. this is my code right now :</p>
  
  <pre><code>Imports System.Net
  </code></pre>
  
  <p>Imports System.Text
  Imports System.IO</p>
  
  <p>Public Class STclass</p>
  
  <pre><code>Dim logincontainer As CookieContainer
  Public Sub check()
      Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://www.stproperty.sg/p/agent/agentad/indexmode=delete"), HttpWebRequest)
      request.CookieContainer = logincontainer
  
      Dim response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse)
  
      Dim reader As New StreamReader(response.GetResponseStream)
  
      Dim theresult As String = reader.ReadToEnd
  
      Form1.WebBrowser1.DocumentText = theresult
  
  
  End Sub
  Public Sub delete()
  
      Dim tempCookies As New CookieContainer
  
      Dim postdata As String = "tab=active&amp;AdForm%5BPTYTYP%5D=&amp;AdForm%5BLISTYP%5D=&amp;active_check%5B%5D=" &amp; Form1.TextBox2.Text &amp; "&amp;massaction=2"
  
  
      Dim enconding As New UTF8Encoding
  
      Dim byteData As Byte() = enconding.GetBytes(postdata)
  
      Dim postrequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.stproperty.sg/p/user/userad/expireListing"), HttpWebRequest)
  
      postrequest.Method = "POST"
      postrequest.KeepAlive = True
      postrequest.CookieContainer = logincontainer
  
      postrequest.ContentType = "application/x-www-form-urlencoded"
      postrequest.Host = "www.stproperty.sg"
      postrequest.Referer = "http://www.stproperty.sg/p/user/userad/index"
      postrequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
  
  
      postrequest.ContentLength = byteData.Length
  
      Dim postreqstream As Stream = postrequest.GetRequestStream
      postreqstream.Write(byteData, 0, byteData.Length)
      postreqstream.Close()
  
      Dim postresponse As HttpWebResponse
      postresponse = DirectCast(postrequest.GetResponse, HttpWebResponse)
  
      'logincontainer.Add(postresponse.Cookies)
  
      ' logincookie = tempCookies
  
      Dim postreader As New StreamReader(postresponse.GetResponseStream)
      Dim thepage As String = postreader.ReadToEnd
  
      Form1.WebBrowser1.DocumentText = thepage
  
  
  End Sub
  
  Public Sub login()
  
      Dim tempCookies As New CookieContainer
      Dim browser As String = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
  
      'get facebook login cookies
  
      Dim firstrequest As HttpWebRequest = WebRequest.Create("http://sphreg.st701.com/RegAuth2/propertyLogin.html?svc=cpy&amp;goto=http%3A%2F%2Fwww.stproperty.sg%2Faccount%2Fdologin")
      firstrequest.CookieContainer = New CookieContainer
      firstrequest.UserAgent = browser
      Dim firstresponse As HttpWebResponse = firstrequest.GetResponse
      tempCookies.Add(firstresponse.Cookies)
  
  
  
  
  
  
      Dim postData As String = "IDToken1=adrian8nairda%40gmail.com&amp;IDToken2=123456&amp;iPSPCookie=false&amp;goto=http%3A%2F%2Fwww.stproperty.sg%2Faccount%2Fdologin"
      Dim encoding As New UTF8Encoding
      Dim byteData As Byte() = encoding.GetBytes(postData)
      Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://sphauth.st701.com/am/UI/Login"), HttpWebRequest)
      postReq.Method = "POST"
      postReq.KeepAlive = True
      postReq.CookieContainer = tempCookies
      postReq.ContentType = "application/x-www-form-urlencoded"
      postReq.Referer = "http://sphreg.st701.com/RegAuth2/propertyLogin.html?svc=cpy&amp;goto=http%3A%2F%2Fwww.stproperty.sg%2Faccount%2Fdologin"
  
      postReq.Host = "sphauth.st701.com"
      postReq.UserAgent = browser
      postReq.ContentLength = byteData.Length
  
  
      'post data to facebook
      Dim postreqstream As Stream = postReq.GetRequestStream()
      postreqstream.Write(byteData, 0, byteData.Length)
      postreqstream.Close()
  
  
      'get cookies and store them
      Dim postresponse As HttpWebResponse
      postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
      tempCookies.Add(postresponse.Cookies)
  
      logincontainer = tempCookies
  
      'check it was all posted correctly
      Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
      Dim thepage As String = postreqreader.ReadToEnd
      Form1.RichTextBox1.Text = thepage
      Form1.WebBrowser1.DocumentText = Form1.RichTextBox1.Text
      Form1.WebBrowser1.ScriptErrorsSuppressed = True
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>Okay.. As you can see I have a login function... and i load the page into a browser, I can see to browse and stuffs.. but then when I try to delete one of my listings I can't, I get prompted to login.. even though I stored the cookies into logincontainer and loaded them before trying to delete. Any help ?</p>