tchiloh -1 Light Poster

i try to open iexplorer without to login. but it likes that the cookie is not saved.
how can i solve this problem?

thit is my code:

public class Web1
  {
    private string URL = "http://test.nl";
    private CookieContainer cook = new CookieContainer();

    public void eerst(string RedmineURL)
    {
      URL += RedmineURL;
    }

    public void Login(string username, string password)
    {
      string authToken = GetAuthToken(URL);
      string postData = String.Format("authenticity_token={0}&username={1}&password={2}", HttpUtility.UrlDecode(authToken), HttpUtility.UrlEncode(username), HttpUtility.UrlEncode(password));
      WebrequestPost(URL, postData, cook);
      System.Diagnostics.Process.Start("iexplore.exe", URL);
    }

    private string GetAuthToken(string url)
    {
      Regex authTokenPattern = new Regex("<input name=\"authenticity_token\" type=\"hidden\" value=\"([^\\\"]*)\" />");
      return authTokenPattern.Match(WebrequestGet(url, cook)).Groups[1].Value;
    }

    private string WebrequestPost(string URL, string PostData, CookieContainer Cookie)
    {
      HttpWebRequest webRequest;
      webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
      webRequest.Method = "POST";
      webRequest.ContentType = "application/x-www-form-urlencoded";
      webRequest.ContentLength = PostData.Length;
      webRequest.CookieContainer = Cookie;
      using (StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()))
      {
        requestWriter.Write(PostData);
      }

      using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
      {
        return responseReader.ReadToEnd();
      }
    }

    private string WebrequestGet(string url, CookieContainer Cookie)
    {
      HttpWebRequest webRequest = HttpWebRequest.Create(url) as HttpWebRequest;
      webRequest.CookieContainer = Cookie;
      StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
      return responseReader.ReadToEnd();
    }
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.