.NET HTTP POST Method - Cookies issue

前端 未结 1 834
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 17:10

I\'m trying to use C# to login to hotfile.com. The first big issue was to overcome the 417 Error, which this line solved it:

System.Net.ServicePointManager.E         


        
相关标签:
1条回答
  • 2020-12-10 17:57

    Here's a working example I wrote for you:

    var cookies = new CookieContainer();
    ServicePointManager.Expect100Continue = false;
    
    var request = (HttpWebRequest)WebRequest.Create("http://www.hotfile.com/login.php");
    request.CookieContainer = cookies;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    using (var requestStream = request.GetRequestStream())
    using (var writer = new StreamWriter(requestStream))
    {
        writer.Write("user=XX&pass=XX&returnto=/");
    }
    
    using (var responseStream = request.GetResponse().GetResponseStream())
    using (var reader = new StreamReader(responseStream))
    {
        var result = reader.ReadToEnd();
        Console.WriteLine(result);
    }
    
    0 讨论(0)
提交回复
热议问题