HttpWebRequest POST and Cookies

后端 未结 1 1391
礼貌的吻别
礼貌的吻别 2021-01-03 17:33

Hi am trying to make an application that post data to a joomla login page but the only thing i get back is cookies is not enabled.

Function GetPage(ByVal Url         


        
相关标签:
1条回答
  • 2021-01-03 17:51

    Try to set .CookieContainer before writing any data to .GetRequestStream()

    Look this sample:

    CookieContainer cookies = new CookieContainer();
    HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(site);
    postRequest.CookieContainer = cookies; // note this
    postRequest.Method = "POST";
    postRequest.ContentType = "application/x-www-form-urlencoded";
    using (Stream stream = postRequest.GetRequestStream())
    {
        stream.Write(buffer, 0, buffer.Length);
    }
    
    0 讨论(0)
提交回复
热议问题