1

我正在用 C# 编写一个窗口应用程序来自动登录并将主题发布到网站。我尝试按照以下方法传递用户名和密码,但 responseText 没有改变。我的意思是,如果我传递了错误的用户名或密码,responseText 将包含“错误文本,例如:错误的密码或用户名”,或者如果我传递给正确的用户名和密码,responseText 将包含“登录成功”,但我收到的 responseText 是就像一个原始的登录页面

你有什么主意吗?太感谢了

    private string Login()
    {
        HttpWebRequest request;

        CookieContainer cookieContainer = new CookieContainer();

        string cookieHeader = string.Empty;

        byte[] byteArray = Encoding.UTF8.GetBytes("username=abc@gmail.com&password=123");

        request = (HttpWebRequest)WebRequest.Create("http://www.vietnamworks.com/dang-nhap");

        request.ContentType = "application/x-www-form-urlencoded";

        request.UserAgent = userAgent;

        request.Method = "POST";

        request.CookieContainer = cookieContainer;

        request.ContentLength = byteArray.Length;

        using (Stream os = request.GetRequestStream())
        {
            os.Write(byteArray, 0, byteArray.Length);
        }

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        string pageSource;

        using (StreamReader sr = new StreamReader(response.GetResponseStream()))
        {
            pageSource = sr.ReadToEnd();
        }

        return pageSource;
    }
4

0 回答 0