帮忙写一份代码。。。。

xingtianzhang2008 2008-02-27 10:02:12
http://www.koubei.com/common/login.html

如何用C#登录到这个网站???


byte[] PostData = Encoding.Default.GetBytes("user.username=abc&user.password=dsfds&hold=1");


string Interface = "http://www.koubei.com/join/login.html";
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Interface);
Request.Method = "POST";
Request.ContentLength = PostData.Length;
Request.ContentType = "application/x-www-form-urlencoded";
Request.AllowAutoRedirect = true;
using (Stream sm = Request.GetRequestStream())
{
sm.Write(PostData, 0, PostData.Length);
sm.Close();
}
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
StreamReader sr = new StreamReader(Response.GetResponseStream(), Encoding.Default);
string s = sr.ReadToEnd();



不能正确登录???

我隐藏了正确的帐号和密码。。
...全文
97 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
umbrella_yang 2008-02-27
  • 打赏
  • 举报
回复
不用这样的,用 WEBCLIENT

具体代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Collections.Specialized;

namespace CMD_POST
{
class Program
{
String Url = ""; //提交的网址
String username = ""; //提交的用户名
String password = ""; //提交的密码
String Speacl = ""; //用来保存特殊特征码字符串
static void Main(string[] args)
{
Program p = new Program();
p.Welcome_Word();
Console.WriteLine();
Console.Write("请输入您的提交网址 (请带上 http:// ) : ");
p.Url = Console.ReadLine();
Console.Write("请输入您的特殊字符 (其中请不要包含特殊字符): ");
p.Speacl = Console.ReadLine();
Console.Write("请输入您的用户名: ");
p.username = Console.ReadLine();
Console.Write("请输入您的密 码: ");
p.password = Console.ReadLine();
p.GetResult();
}

//欢迎词
public void Welcome_Word()
{
Console.WriteLine("************* 欢迎使用C# POST 提交器 *************");
Console.WriteLine();
Console.WriteLine(" 作者:剑走偏锋 [E.S.T] ");
Console.WriteLine();
Console.WriteLine("************* 请输入如下数据 *************");
}

//创建对象
public void GetResult()
{
WebClient web = new WebClient();
NameValueCollection vc = new NameValueCollection();
vc.Add("username", this.username);
vc.Add("password",this.password);
String ReturnMess = "";
int i = 0;
try
{
byte[] byRemoteInfo = web.UploadValues(this.Url,"POST",vc);
ReturnMess = Encoding.UTF8.GetString(byRemoteInfo);
for (i = 0 ; i < ReturnMess.Length ; i++)
{
if (ReturnMess.IndexOf(this.Speacl) > 0)
{
Console.WriteLine("密码找到了!");
Console.WriteLine("帐户:" + this.username + " 密码:" + this.password);
break;
}
//Length += 9;
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("出现错误 : 请检查您所输入的信息是否正确......");
}
}
}
}


如果需要实例 请来找我
必须首先给分结贴!!!
QQ:250623008
邮箱:umbrella_yang@jinpai.com

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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