c#模拟http post 带cookie
下面的代码是自动向cnblogs中的小组发帖.........注意小组ID,主题ID,小组类型
首先采用firebug分析到发帖时的post地址以及参数,其中在headers中包含了cookies,把cookies复制下来放到d:\cookie.txt中,以分号隔开(a=b;c=d;),这些cookie中包含有身份验证信息
之后读取文件d:\data.txt,每1024个字节为一帖自动发送
代码
using System;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections;
using System.Net;
using System.Threading;
namespace Haier1
{
class Program
{
public static Hashtable getCookieMap()
{
string sPath = "d:\cookie.txt";
Hashtable maps = new Hashtable();
FileStream fs = new FileStream(sPath, FileMode.Open);
StreamReader rf = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));
string hm = "";
try
{
do
{
hm = rf.ReadLine();
} while (!rf.EndOfStream);
Console.WriteLine(hm);
String[] s1 = hm.Split(;);
// Console.Write(s1.Length);
for (int i = 0; i < s1.Length; i++)
{
int pos = s1[i].IndexOf(=);
using System.Collections.Generic;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;
using System.Collections;
using System.Net;
using System.Threading;
namespace Haier1
{
class Program
{
public static Hashtable getCookieMap()
{
string sPath = "d:\cookie.txt";
Hashtable maps = new Hashtable();
FileStream fs = new FileStream(sPath, FileMode.Open);
StreamReader rf = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));
string hm = "";
try
{
do
{
hm = rf.ReadLine();
} while (!rf.EndOfStream);
Console.WriteLine(hm);
String[] s1 = hm.Split(;);
// Console.Write(s1.Length);
for (int i = 0; i < s1.Length; i++)
{
int pos = s1[i].IndexOf(=);
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,
部份技术文章来自网络,