关于网站自动登录的问题

csdnuser2004 2004-06-21 10:40:39
我看了csdn上关于自动登录csdn的例子http://dev.csdn.net/Develop/article/28/28374.shtm。现有问题如下:
1、我建了asp.net中的web应用程序,点击提交后,通过了csdn的验证页面,但跳转时却到了http://localhost/Member/Passport.asp正确的应该为http://www.csdn.net/Member/Passport.asp。不知到谁的自动登录csdn的例子是成功的?
2、自动登录csdn网站的数据提交方式是login_name=aa&password=111111&cookietime=0。

我现在有一个aspx网站页面,用“Visual Sniffer”工具查看它的数据提交格式是:
POST /register.aspx HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://www.aaa.com.cn/register.aspx
Accept-Language: zh-cn
Content-Type: multipart/form-data; boundary=---------------------------7d42bf2030536
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Host: www.aaa.com.cn
Content-Length: 4272
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: mytongji=yes

-----------------------------7d42bf2030536
Content-Disposition: form-data; name="__EVENTTARGET"


-----------------------------7d42bf2030536
Content-Disposition: form-data; name="__EVENTARGUMENT"


-----------------------------7d42bf2030536
Content-Disposition: form-data; name="__VIEWSTATE"

fZm9jdXM6OTtjYmxfZm9jdXM6MTA7Y2JsX2ZvY3VzOjExO2NibF9mb2N1czoxMjtjYmxfZm9jdXM6MTM7Y2JsX2ZvY3VzOjE0O2NibF9mb2N1czoxNTtjYmxfZm9jdXM6MTY7Y2JsX2ZvY3VzOjE3O2NibF9mb2N1czoxODtjYmxfZm9jdXM6MTg7cmJfc2VsZWN0X2FsbDtyYl9zZWxlY3RfYWxsO3JiX3Vuc2VsZWN0O3JiX3Vuc2VsZWN0Oz4+EB/9uwGkB3Nh2IFt953tttyoEzg=
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="tb_username"

rere
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="tb_password"

rere
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="tb_password_again"

rere
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="ddl_member_type"

1
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="tb_name"

fdsfdsf
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="tb_address"

fdsfsdf
-----------------------------7d42bf2030536
Content-Disposition: form-data; name="btn_submit"

提交

请问数据提交这块的格式怎么写?谢谢!!!
...全文
336 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnuser2004 2004-06-23
  • 打赏
  • 举报
回复
我说了问题的背景是http://dev.csdn.net/Develop/article/28/28374.shtm
不是我的应用程序要实现让用户自动登录;而是我写程序去自动登录别人的网站。不知道其他朋友都理解成什么了?也许是没看http://dev.csdn.net/Develop/article/28/28374.shtm
raymond323 2004-06-23
  • 打赏
  • 举报
回复
use cookie
elite2018 2004-06-23
  • 打赏
  • 举报
回复
use cookie
dub 2004-06-23
  • 打赏
  • 举报
回复
注意下面的例子中:webRqst.ContentType = "multipart/form-data; boundary=xyz";
所以数据提交部份实际上是从你的boundary也就是
-----------------------------7d42bf2030536开始到结束。
以下是一个例子:

System.Uri uri = new Uri(msp_url);
string dataBoundary = "--xyz";
System.Net.HttpWebRequest webRqst = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(uri);

//add existing cookies to the webrequest.
webRqst.CookieContainer = new CookieContainer();
webRqst.CookieContainer.Add(mspCookies);

//create the WebRequest Content-Body manually for file upload.
webRqst.ContentType = "multipart/form-data; boundary=xyz";
webRqst.Method = "POST";
webRqst.KeepAlive = true;

//get the file content that will be uploaded.
StreamReader sr = new StreamReader(filepath);
string FileData = sr.ReadToEnd(); // test data to send.
sr.Close();

//make a string to store the content.
StringBuilder DataString = new StringBuilder();

DataString.Append(dataBoundary + "\r\n");
DataString.Append("Content-Disposition: form-data; name=\"filename\"\r\n\r\n" + "test.txt\r\n");

DataString.Append(dataBoundary + "\r\n");
DataString.Append("Content-Disposition: form-data; name=" + "\"submitFile\"" +
"; filename=" + "\"" + filename + "\"" + "\r\n");
DataString.Append("Content-Type: text/plain\r\n\r\n");
DataString.Append(FileData);
DataString.Append(dataBoundary + "--\r\n");

byte []Postdata = System.Text.Encoding.Default.GetBytes(DataString.ToString());

//change the requests content length to the size of data being posted in request.
webRqst.ContentLength = Postdata.Length;

//get the response stream from the webrequest and write the data to be posted to the
//Request Stream

Stream tempStream = webRqst.GetRequestStream();
tempStream.Write(Postdata,0,Postdata.Length);
tempStream.Flush();
tempStream.Close();


//change certificate policy to always allow.
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
System.Net.HttpWebResponse webRsp = (System.Net.HttpWebResponse)webRqst.GetResponse();
bizbuy 2004-06-21
  • 打赏
  • 举报
回复
你把项目传到服务器上应该可以吧。

可能登录认证之后用的是相对路径,所以转到Passport.asp去了。
jpyc 2004-06-21
  • 打赏
  • 举报
回复
放在COOKIES里,自动读取的
QQSugar 2004-06-21
  • 打赏
  • 举报
回复
vzxq 2004-06-21
  • 打赏
  • 举报
回复
学习,我觉的用cookies

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧