none
Handlling cookies RRS feed

  • 常规讨论

  • Hi all,
            I am new to .net. I want to log in to a web site(PHP) problematically and update and read my data. I am usingSystem.Net.CookieContainer to maintain cookies. What I am doing is sending back that cookies comes with responds. I am getting time-out errors. There are two domain names in inside of the object(one with a prefix of "." eg: www.test.te and www.test.te). Here is my coding.

     
    Stream os = null;
                try
                { // send the Post
                    webRequest.ContentLength = bytes.Length;   //Count bytes to send
                    os = webRequest.GetRequestStream();
                    os.Write(bytes, 0, bytes.Length);         //Send it
                }
                catch (WebException ex)
                {
                    //ex.Message = "Failed to send data to "+url+". Because " + ex.Message;
                    throw ex;
                }
                finally
                {
                    if (os != null)
                    {
                        os.Close();
                    }
                }
    
                try
                { // get the response
                    HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                    if (webResponse == null)
                    { return null; }
                    StreamReader sr = new StreamReader(webResponse.GetResponseStream());
                    MyWebInfo.CookiesContainer.Add(webResponse.Cookies);
                    return sr.ReadToEnd().Trim();
    I set 
    MyWebInfo.CookiesContainer
     as cookie container as next request

    webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.Method = "POST";
                // webRequest.CookieContainer = new CookieContainer();
                webRequest.CookieContainer = MyWebInfo.CookiesContainer;
                byte[] bytes = Encoding.ASCII.GetBytes(parameters);
    It is not working properly. If some one can tell me the correct way it is a great help. I tried to do then for a long time
    Thanks in advance
    Manjula
    2009年7月26日 17:36