HTTPS Post请求登录C#

时间:2017-08-30 10:23:46

标签: c# login http-post

凌晨1点尝试使用帖子请求登录扑克网站。但我没有得到正确的答复。我正在获取原始登录页面的来源。

我知道凭据是正确的,因为它们是手动工作的。

以下是尝试登录的代码段。根据我的理解,响应源代码应该是成功登录的代码。

static void Main(string[] args)
{
    string username = "####";
    string password = "########";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ftrpoker.com/login.html");
    request.Method = "POST";
    using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
    {
        writer.Write("USERNAME=" + username + "&PASSWORD=" + password);
    }

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        Console.WriteLine(reader.ReadToEnd());
}

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题。尝试使用附加到ServicePointManager.ServerCertificateValidationCallback的RemoteCertificateValidationCallback。

这样的事情:

private static bool ValidateRemoteCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors policyErrors)
{
    return true;
}

解决方案来自: https://social.msdn.microsoft.com/Forums/vstudio/en-US/2acefdc1-be7f-4dc1-a5f0-61cceed2958c/posting-using-post-from-c-over-https?forum=netfxbcl