相关疑难解决方法(0)

使用Cookies的C#WebRequest

我有一个winforms应用程序,我一直在努力对消费者帐户进行多项测试.测试需要一次登录才能执行.

string paramaters = "authmethod=on&chkRememberMe=on&login-form-type=pwd&password=" + pw.Text + "&userid=" + uid.Text + "&username=" + uid.Text;
        string strResponse;
        HttpWebRequest requestLogin = (HttpWebRequest)WebRequest.Create("https://www.url.com/login.form");
        requestLogin.Method = "POST";
        requestLogin.CookieContainer = cookieJar;
        requestLogin.ContentType = "application/x-www-form-urlencoded";

        requestLogin.ContentLength = paramaters.Length;
        StreamWriter stOut = new StreamWriter(requestLogin.GetRequestStream(), System.Text.Encoding.ASCII);
        stOut.Write(paramaters);
        stOut.Close();

        StreamReader stIn = new StreamReader(requestLogin.GetResponse().GetResponseStream());
        strResponse = stIn.ReadToEnd();
        stIn.Close();
Run Code Online (Sandbox Code Playgroud)

这个脚本适用于登录就好了,问题是当我需要实际运行测试时我需要将所有结果都返回到一个字符串中(HTML结果).

private string runTestRequest(Uri url, string parameters)
    {
        string testResults = string.Empty;
        HttpWebRequest runTest = (HttpWebRequest)WebRequest.Create(url);
        runTest.CookieContainer = cookieJar;
        runTest.Method = "POST";
        runTest.ContentType = "application/x-www-form-urlencoded";
        StreamWriter stOut = new StreamWriter(runTest.GetRequestStream(), …
Run Code Online (Sandbox Code Playgroud)

c# cookies webrequest winforms

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

cookies ×1

webrequest ×1

winforms ×1