日期:2014-05-17  浏览次数:20860 次

Post登陆某网站,出现401,求解决

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

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

        const string LoginUrl = @"http://www.19lou.com/login";
        HttpWebRequest httpWebRequest;
        HttpWebResponse httpWebResponse;
        string responseFromServer;              //SendLogin返回的响应流
        string username = ""; //username
        string password = ""; //password
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (txt_username.Text != "" && txt_password.Text != "")
            {
                username = txt_username.Text;
                password = txt_password.Text;
                string PostData = string.Format("userName={0}&userPass={1}&captcha=&checked=0&cityInfo=&refererUrl=aHR0cDovL3d3dy4xOWxvdS5jb20=&remember=1", username, password);
                SendLogin(LoginUrl, PostData);
            }
        }



        public void SendLogin(string loginUrl, string postData)
        {
            byte[] byteArray = Encoding.GetEncoding("GBK").GetBytes(postData);
            try
            {
                //基于apache服务器,IIS发布的则不需要  
                ServicePointManager.Expect100Continue = false;
                CookieContainer cookieContainer = new CookieContainer();
                //创建对url的请求  
  &nbs