cookie 本来就是会提交上去的
解决方案 »
- C# 多线程下载 只能下载7.2KB什么问题,高手帮我看看?
- 怎么在窗体关闭时,由于窗体中的数据没有完全保存而阻止窗体的关闭?
- c#事务处理
- 在线求 C# 写的把数据转大写的程序!
- 如何更换文件.exe图 标?
- .net写的Com组件用log4net记录异常日志,为何记录不了!
- 100分求教一datagrid的难题!找遍了所以的地方也没找到类似的问题!
- 如何实现C#winform中右击combobox下拉选项中的某一项弹出右键菜单?
- sbyte[]转换为string
- How to make a ListView control display an item for a line?
- c#求指点DLL 文件中类的继承
- 关于C#数据库连接的问题
static System.Text.Encoding encoding = System.Text.Encoding.UTF8;
public string Post(string url, NameValueCollection nvc)//提交数据
{
StringBuilder sb = new StringBuilder();
foreach (string key in nvc.AllKeys)
{
sb.Append(key + "=" + HttpUtility.UrlEncode(nvc[key]) + "&");
}
HttpWebRequest wc = (HttpWebRequest)HttpWebRequest.Create(url);
wc.CookieContainer = cc;
if (!string.IsNullOrEmpty(sb.ToString()))
{
wc.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, */*";
wc.ContentType = "application/x-www-form-urlencoded";
wc.Referer = "http://oa.plusbe.com/Admin/Login.aspx";
wc.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Shuame)";
wc.Headers.Add("Accept-Language", "zh-cn");
wc.Headers.Add("UA-CPU", "x86");
wc.AllowAutoRedirect = true;
wc.Method = "POST";
string postData = sb.ToString().TrimEnd('&');
byte[] postBuffer = encoding.GetBytes(postData);
wc.ContentLength = postBuffer.Length;
using (Stream stream = wc.GetRequestStream())
{
stream.Write(postBuffer, 0, postBuffer.Length);
stream.Flush();
stream.Close();
}
}
using (HttpWebResponse res = (HttpWebResponse)wc.GetResponse())//处理接收
{
Stream response = res.GetResponseStream();
if (wc.CookieContainer != null)
{
res.Cookies = wc.CookieContainer.GetCookies(wc.RequestUri);
}
string responseUrl = res.ResponseUri.ToString();
StreamReader sr = new StreamReader(response);
string c = sr.ReadToEnd();
Console.WriteLine(c);
return c;
}
} public string GetVerifyCode(string sourceUrl, string saveVirtualAddress)//获取验证码
{
CookieContainer cc = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sourceUrl);
req.CookieContainer = cc;
using (WebResponse res = req.GetResponse())
{ System.Drawing.Image bmp = Bitmap.FromStream(res.GetResponseStream());
string fn = System.IO.Path.Combine(SysConfig.ApplicationPath + saveVirtualAddress.TrimEnd('/') + "/", Guid.NewGuid().ToString() + ".jpg");
string address = HttpContext.Current.Server.MapPath(fn);
bmp.Save(address, ImageFormat.Jpeg);
return fn;
}
}源码。。cc一直未空
request.CookieContainer = new CookieContainer();
foreach (string ItemName in Request.Cookies.AllKeys)
{
request.CookieContainer.Add(new Cookie
{
Name = Request.Cookies[ItemName].Name,
Value = Request.Cookies[ItemName].Value,
Domain = Request.Cookies[ItemName].Domain,
HttpOnly = Request.Cookies[ItemName].HttpOnly,
Expires = Request.Cookies[ItemName].Expires,
Path = Request.Cookies[ItemName].Path
});
}
wc.Method = "POST"; 改成 GET
v.Add("username", "xingch50");
v.Add("password", "mygoogle");
v.Add("checkNum", code);
string ceshi = Post(url, v);