日期:2014-05-18  浏览次数:20747 次

小妹求救https访问返回结果不变的问题
环境IIS7 证书利用IIS设置里的创建自签名证书。

主要问题,我设立了一个网站用https方式访问。

获取两个参数,返回页面一个OK和Error的值。

WinForm里访问这个网站,但是每次访问得到的结果都是一个,

均返回“OK”,无论怎么修改传递的值都一样,请帮我看看哪里出问题了!


Default.aspx
C# code

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SSLWeb
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string user_name=Request.QueryString["user_name"];
            string password = Request.QueryString["password"];

            if (user_name == "admin" && password == "admin")
            {
                Response.Write("OK");
            }
            else
            {
                Response.Write("Error");
            }
        }
    }
}



WinForm窗体代码
C# code

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
using System.Security.Cryptography.X509Certificates;
using System.Security.Authentication;
using System.Net;
using System.Net.Security;
using System.Windows.Forms;

namespace SSLWindows
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                string loginUrl = "https://192.168.0.62/Default.aspx";
                string userName = "admin";//重点这里传递任何值返回值都是一样的
                string password = "admin";
                Encoding encoding = Encoding.GetEncoding("gb2312");

                IDictionary<string, string> parameters = new Dictionary<string, string>();

                parameters.Add("user_name", userName);
                parameters.Add("password", password);
                HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl,
                    parameters, null,null, encoding,null);
                
                //StreamReader re = new StreamReader(request.GetResponse().GetResponseStream());
                string cookieString = response.StatusDescription;
                if (cookieString == null)
                {
                    MessageBox.Show("null");
                }
                else
                {
                    MessageBox.Show(cookieString);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
}


HttpWebResponseUtility.cs
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Security;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace SSLWindows
{
    public class HttpWebResponseUtility
    {
        private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; "
            +".NET CLR 1.1.4322; .NET CLR 2.0.50727)";

        /// <summary>
        /// 创建POST方式的HTTP请求
        /// </summary>
        /// <param name="url">请求的URL</param>
        /// <param name="parameters">随同请求POST的参数名称及参数值字典</param>
        /// <param name="timeout">请求的超时时间</param>
        /// <