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

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

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

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

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

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

Default.aspx 这个是Https访问的地址
C# code

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

                StreamWriter writer = new StreamWriter("D:\\test.txt");
                writer.WriteLine("user_name:" + user_name);
                writer.WriteLine("password:" + password);
                writer.WriteLine("Time:" + System.DateTime.Now);

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



WinForm.cs
C# code

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

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                #region Get方法
                string userName = "1";
                string password = "1";
                string tagUrl = "https://192.168.0.62/Default.aspx?user_name="+userName+"&password="+password;
                CookieCollection cookies = new CookieCollection();
                HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(tagUrl, null, null, cookies);
                string cookieString = response.StatusDescription;
                if (cookieString == null)
                {
                    MessageBox.Show("null");
                }
                else
                {
                    MessageBox.Show(cookieString);
                }
                #endregion

                #region Post方法
                //string loginUrl = "https://192.168.0.62/Default.aspx";
                //string userName = "1";
                //string password = "1";
                //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);
                //}
            #endregion
            }
            ca