我学习模拟登陆 然后就找到了这位大哥的文章 地址如下:http://blog.csdn.net/htsnoopy/article/details/7094224前边的我按照所写感觉都很顺利 但是到 最后一段代码的时候 遇到麻烦了
我已经将前边的方法都放入了类中,然后复制代码进了控制台代码中 然后就提示好多错误,哪位高手给指点指点 最后一段代码应该怎么修改 代码如下
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
HttpHeader header = new HttpHeader();
header.accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
header.contentType = "application/x-www-form-urlencoded";
header.method = "POST";
header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
header.maxTry = 300;
CookieCollection mycookie = HTMLHelper.GetCookieCollection("http://www.renren.com/PLogin.do",
"email=aaa%40163.com&password=111&icode=&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&domain=renren.com&key_id=1&_rtk=90484476", header);
foreach (Cookie cookie in mycookie) //将cookie设置为浏览的cookie
{
InternetSetCookie(
"http://" + cookie.Domain.ToString(),
cookie.Name.ToString(),
cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
System.Diagnostics.Process.Start("http://guide.renren.com/guide");
我已经将前边的方法都放入了类中,然后复制代码进了控制台代码中 然后就提示好多错误,哪位高手给指点指点 最后一段代码应该怎么修改 代码如下
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
HttpHeader header = new HttpHeader();
header.accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
header.contentType = "application/x-www-form-urlencoded";
header.method = "POST";
header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
header.maxTry = 300;
CookieCollection mycookie = HTMLHelper.GetCookieCollection("http://www.renren.com/PLogin.do",
"email=aaa%40163.com&password=111&icode=&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&domain=renren.com&key_id=1&_rtk=90484476", header);
foreach (Cookie cookie in mycookie) //将cookie设置为浏览的cookie
{
InternetSetCookie(
"http://" + cookie.Domain.ToString(),
cookie.Name.ToString(),
cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
System.Diagnostics.Process.Start("http://guide.renren.com/guide");
错误 1 “Test.HTMLHelper.InternetSetCookie(string, string, string)”不能是外部的,也无法声明主体 D:\我的文档\Visual Studio 2008\Projects\myrrlogin\myrrlogin\test.cs 146 35 myrrlogin
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace myrrlogin
{
class Program
{
static void Main(string[] args)
{
//HttpHeader header = new Test.HttpHeader();
//header.accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
//header.contentType = "application/x-www-form-urlencoded";
//header.method = "POST";
//header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
//header.maxTry = 300; //string html = Test.HTMLHelper.GetHtml("http://guide.renren.com/guide", Test.HTMLHelper.GetCooKie("http://www.renren.com/PLogin.do",
// "email=bgaidu%40163.com&password=123456789&origURL=https%3A%2F%2Fsafe.renren.com%2F&domain=renren.com&formName=&method=&isplogin=true&submit=%E7%99%BB%E5%BD%95", header), header); //Console.WriteLine(html);
//Console.ReadLine(); foreach (Cookie cookie in mycookie) //将cookie设置为浏览的cookie
{
InternetSetCookie( "http://" + cookie.Domain.ToString(), cookie.Name.ToString(),cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
System.Diagnostics.Process.Start("http://guide.renren.com/guide");
}
[System.Runtime.InteropServices.DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData)
{
HttpHeader header = new HttpHeader();
header.accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
header.contentType = "application/x-www-form-urlencoded";
header.method = "POST";
header.userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
header.maxTry = 300;
CookieCollection mycookie = HTMLHelper.GetCookieCollection("http://www.renren.com/PLogin.do",
"mail=bgaidu%40163.com&password=123456789&origURL=https%3A%2F%2Fsafe.renren.com%2F&domain=renren.com&formName=&method=&isplogin=true&submit=%E7%99%BB%E5%BD%95", header); }
}
}然后就出上边的错误