想写一个刷投票的东西,要传的数据流信息如下
GET /puyp/cookie.jsp 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://it.jxcn.cn/tp/index.htm
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; 51Logon.com; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Creative AutoUpdate v1.10.10)
Host: it.jxcn.cn
Connection: Keep-Alive
Cookie: JSSSINid=NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTU
POST /puyp/vote.php 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://it.jxcn.cn/tp/index.htm
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; 51Logon.com; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Creative AutoUpdate v1.10.10)
Host: it.jxcn.cn
Content-Length: 85
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTUCSid=521232&action=posttp
我代码是下面这样子(参照网上的文章来做的)
WebClient myWebClient = new WebClient();//申明并创建WebClient实例myWebClient
byte[] byteArray;//申明存储提交数据的变量
byte[] responseArray;//申明存储接收数据的变量//设置HTTP头信息,并非所以的信息都需要设置,以下这些信息足够了
myWebClient.Headers.add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
myWebClient.Headers.Add("Referer", "http://www.outdosz.cn/generalvote/webvote/vote.asp");
myWebClient.Headers.Add("Accept-Language", "zh-cn");
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
myWebClient.Headers.Add("Accept-Encoding", "gzip, deflate"); byteArray = Encoding.Default.GetBytes(voteDATA);//将提交的数据转化为byte数组 try
{
responseArray = myWebClient.UploadData("http://www.outdosz.cn/generalvote/webvote/savevote.asp", "POST", byteArray);//提交投票信息,并获取返回的数据
}
catch (Exception exPOST)
{
errorMessage = "\nPOST方式投票时出现错误,错误信息为:" + exPOST.Message;
myWebClient.Dispose();//释放myWebClient所占用的资源
return false;//提示错误信息并返回。
}
myWebClient.Dispose();//释放myWebClient所占用的资源
outputMessage = "\n接收的正文信息:\n";
outputMessage = outputMessage + Encoding.Default.GetString(responseArray);
return true;现在有个问题 就是我如何在提交之前取得
Cookie: JSSSINid=NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTU
Cookie里的值
还有就是如何在Post的时候把Cookie也Post过去呢?
小弟新人想学习,如果回贴说要我用网上的那些刷票软件就算了。
肯请大家指点~!
GET /puyp/cookie.jsp 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://it.jxcn.cn/tp/index.htm
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; 51Logon.com; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Creative AutoUpdate v1.10.10)
Host: it.jxcn.cn
Connection: Keep-Alive
Cookie: JSSSINid=NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTU
POST /puyp/vote.php 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://it.jxcn.cn/tp/index.htm
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; 51Logon.com; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Creative AutoUpdate v1.10.10)
Host: it.jxcn.cn
Content-Length: 85
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTUCSid=521232&action=posttp
我代码是下面这样子(参照网上的文章来做的)
WebClient myWebClient = new WebClient();//申明并创建WebClient实例myWebClient
byte[] byteArray;//申明存储提交数据的变量
byte[] responseArray;//申明存储接收数据的变量//设置HTTP头信息,并非所以的信息都需要设置,以下这些信息足够了
myWebClient.Headers.add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
myWebClient.Headers.Add("Referer", "http://www.outdosz.cn/generalvote/webvote/vote.asp");
myWebClient.Headers.Add("Accept-Language", "zh-cn");
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
myWebClient.Headers.Add("Accept-Encoding", "gzip, deflate"); byteArray = Encoding.Default.GetBytes(voteDATA);//将提交的数据转化为byte数组 try
{
responseArray = myWebClient.UploadData("http://www.outdosz.cn/generalvote/webvote/savevote.asp", "POST", byteArray);//提交投票信息,并获取返回的数据
}
catch (Exception exPOST)
{
errorMessage = "\nPOST方式投票时出现错误,错误信息为:" + exPOST.Message;
myWebClient.Dispose();//释放myWebClient所占用的资源
return false;//提示错误信息并返回。
}
myWebClient.Dispose();//释放myWebClient所占用的资源
outputMessage = "\n接收的正文信息:\n";
outputMessage = outputMessage + Encoding.Default.GetString(responseArray);
return true;现在有个问题 就是我如何在提交之前取得
Cookie: JSSSINid=NjhlNDcyZjFmY2ZkDGYDgwZTU1YzRjMDRkZTc0OTU
Cookie里的值
还有就是如何在Post的时候把Cookie也Post过去呢?
小弟新人想学习,如果回贴说要我用网上的那些刷票软件就算了。
肯请大家指点~!
public class HttpWebClient:WebClient
{
private CookieContainer cookie ;
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request ;
request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
HttpWebRequest httpRequest = request as HttpWebRequest; httpRequest.CookieContainer = cookie;
} return request;
}
public HttpWebClient(CookieContainer cookie)
{
this.cookie = cookie;
}
}
http://topic.csdn.net/t/20050413/14/3933091.html
通常请求一次服务器就可以,如果需要登录的话则把登录信息发送到登录页。读取Respose的Hreader或是Cookies
写入Cookie参考楼上 或使用Header.Add();