请问c# winform post带cookie提交

beijixuem 2011-07-15 03:41:35
谁哪里有例子呢?比如人人网的....天涯论坛的等等,希望有的能给我发一份,一定要能用呀,从网上找了几个,都不行!我的邮箱地址是:531533866@qq.com
发了的,记着在下面留言,直接给分!200
...全文
677 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dalmeeme 2011-07-16
  • 打赏
  • 举报
回复
发了,改下登录名和密码就可以了。
beijixuem 2011-07-16
  • 打赏
  • 举报
回复
好的,可以的,谢谢了。531533866@qq.com
dalmeeme 2011-07-16
  • 打赏
  • 举报
回复
我有一个自动登录csdn的,采集自己的分数情况,一个小例子。不知你要吗?
beijixuem 2011-07-16
  • 打赏
  • 举报
回复
求助呀,有没有人做过的?
beijixuem 2011-07-15
  • 打赏
  • 举报
回复
????
wangyue4 2011-07-15
  • 打赏
  • 举报
回复
之后的页面获取操作比如论坛的发帖等使用myCookieContainer 即可
wangyue4 2011-07-15
  • 打赏
  • 举报
回复
CookieContainer myCookieContainer = new CookieContainer();//cookie,全局的

//登陆url,返回登录成功后网页代码,paramList为登录的提交字符串
public string Login(String url, String paramList)
{
HttpWebResponse res = null;
string strResult = "";
string postdata = null;

try
{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
//req.AllowAutoRedirect = false;
req.AllowWriteStreamBuffering = false;//禁用数据缓存
//if (myCookieContainer!=null)
//{
req.CookieContainer = myCookieContainer;
//}
//req.Connection = "keep - alive";
postdata = bianma(paramList);

byte[] data = Encoding.GetEncoding(charset).GetBytes(postdata);
req.ContentLength = data.Length;
Stream strm = req.GetRequestStream();
strm.Write(data, 0, data.Length); //写入参数
strm.Close();
res = (HttpWebResponse)req.GetResponse();
res.Cookies = myCookieContainer.GetCookies(req.RequestUri);
//myCookieContainer.Add(res.Cookies);
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding(charset);
StreamReader sr = new StreamReader(ReceiveStream, encode);

strResult = sr.ReadToEnd();
}
catch (Exception e)
{
strResult = e.ToString();
}
finally
{
if (res != null)
{
res.Close();
}
}


return strResult;
}


/// <summary>
//对参数字符串进行URL编码
/// </summary>
public string bianma(string postData)//对参数字符串进行URL编码
{
Encoding e1 = Encoding.GetEncoding(charset);
int i = 0, j;
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = { '?', '=', '&' };
while (i < postData.Length)
{
j = postData.IndexOfAny(reserved, i);//报告指定 Unicode 字符数组中的任意字符在此实例中第一个匹配项的索引。该搜索从指定字符位置开始。
//j = 0 j=11
if (j == -1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(postData.Substring(i, postData.Length - i), e1));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(postData.Substring(i, j - i), e1));
//在此实例的结尾追加指定对象的字符串表示形式
//HttpUtility提供用于在处理 Web 请求时编码和解码 URL 的方法。
//UrlEncode()方法对 URL 字符串进行编码。
//Append函数在此实例的结尾追加指定数组的Unicode字符的字符串表示形式
UrlEncoded.Append(postData.Substring(j, 1));
i = j + 1;
}
// Encoding.Unicode.GetString(UrlEncoded);
return UrlEncoded.ToString();

}



beijixuem 2011-07-15
  • 打赏
  • 举报
回复
本想给200的 结果最多只能输入100
白鸽 2011-07-15
  • 打赏
  • 举报
回复
现成的没有,等其他人吧

110,538

社区成员

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

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

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