0

我正在尝试编写登录脚本,但由于某种原因,我收到了内部服务器错误 (500)。

我用 PHP 和 cURL 试过这个,当我设置选项时我得到了一个响应VERIFY_PEER = false

这是 C# 代码:

    private void Login()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://whatever.com");
        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = string.Format("user={0}&password={1}&submit=login", User, Password);
        byte[] data = Encoding.ASCII.GetBytes(postData);
        webRequest.Method = "POST";
        ServicePointManager.ServerCertificateValidationCallback = (x,y,z,a) => true;
        webRequest.ContentLength = data.Length;
        webRequest.KeepAlive = false;
        using (Stream stream = webRequest.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }
        using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())
        {
            using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
            {
                Console.WriteLine(responseStream.ReadToEnd());
            }
        }
    }

有人知道为什么我没有得到回复吗?

谢谢你的帮助。

4

2 回答 2

0

我建议使用Fiddler来检查 HTTP 请求/响应。您也可以将其设置为拦截 HTTPS 流量。这样你就可以准确地看到你的系统正在请求什么。

从您的评论中,您收到 500 错误,这通常意味着如果 url/request 从一个脚本/应用程序而不是另一个脚本/应用程序工作,则它的格式不正确。这将使您看到正在请求的内容(并为您突出显示任何协议错误)。

于 2012-07-23T11:24:52.410 回答
0

我发现了错误......似乎服务器需要一个“有效”的用户代理。将 firefox 设置为用户代理时,一切正常。

于 2012-07-23T13:10:51.253 回答