首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

至于自动登陆网站代码改写后不能正常登录求助

2011-12-24 
关于自动登陆网站代码改写后不能正常登录求助usingSystemusingSystem.DatausingSystem.Configurationus

关于自动登陆网站代码改写后不能正常登录求助
using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;
using   System.Text;
using   System.Net;
using   System.IO;

public   partial   class   CJ_Default   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {


                string   username   =   "hbgjh ";
                string   password   =   "hbgjh ";

                ASCIIEncoding   encoding   =   new   ASCIIEncoding();
                string   postData   =   "userName= "   +   username;
                postData   +=   ( "&PassWord= "   +   password);

                byte[]   data   =   encoding.GetBytes(postData);

                //   Prepare   web   request...
                HttpWebRequest   myRequest   =
                (HttpWebRequest)WebRequest.Create( "http://www.locknet.com.cn/member/checklogin.asp ");

                myRequest.Method   =   "POST ";
                myRequest.ContentType   =   "application/x-www-form-urlencoded ";
                myRequest.ContentLength   =   data.Length;
                Stream   newStream   =   myRequest.GetRequestStream();

                //   Send   the   data....
                newStream.Write(data,   0,   data.Length);
                newStream.Close();

                //   Get   response
                HttpWebResponse   myResponse   =   (HttpWebResponse)myRequest.GetResponse();
                StreamReader   reader   =   new   StreamReader(myResponse.GetResponseStream(),   Encoding.Default);
                string   content   =   reader.ReadToEnd();
                Response.Write(content);


        }
}

以上源码是网上“C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
”文章根据我自己实际要求改写.
                string   username   =   "hbgjh ";
                string   password   =   "hbgjh ";
是http://www.locknet.com.cn   是我实验网站的一个正确的账号。


请各位指导修改。谢谢!

[解决办法]
string postData = "userName= " + username;
postData += ( "&PassWord= " + password);
postData += "&Submit32.x=62&Submit32.y=9 ";
[解决办法]
string postData = "username=hbgjh&password=hbgjh&Submit32.x=62&Submit32.y=9 ";
[解决办法]
你得用嗅包器看你实际向服务器提交的数据

热点排行