0

我正在尝试使用以下网页中的以下代码通过 C# 提交 HTML 表单:

http://liga.record.xl.pt/User/Login.aspx

我无法进入页面。那是因为它使用javascript登录吗?

private String readHtmlPage(string url)
    {
        String email = "email";
        String password = "password";

        String result = "";
        String strPost = "email=" + email + "&password=" + password; 
        StreamWriter myWriter = null;

        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
        objRequest.Method = "POST";
        objRequest.ContentLength = strPost.Length;
        objRequest.ContentType = "application/x-www-form-urlencoded";

        try
        {
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            myWriter.Write(strPost);
        }
        catch (Exception e)
        {
            return e.Message;
        }
        finally
        {
            myWriter.Close();
        }

        HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
        using (StreamReader sr =
           new StreamReader(objResponse.GetResponseStream()))
        {
            result = sr.ReadToEnd();

            // Close and clean up the StreamReader
            sr.Close();
        }
        return result;
    }
4

0 回答 0