资源简介
c#下的http请求通用类(自动实现保留上传请求cookie,自动登录)。调用getUrlResponse方法可以获取HttpWebResponse请求对象,调用getUrlRespHtml方法可以获取请求获得的html内容。还可以设置代理IP地址。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.Regularexpressions;
using System.Web;
public class publicPost
{
CookieCollection curCookies = new CookieCollection();
//WebProxy pro = new WebProxy(“172.16.201.240“ 808);//代理地址
public bool isContainCookie(object ckToCheck object cookies)
{
bool isContain = false;
if ((ckToCheck != null) && (cookies != null))
{
string ckName = ““;
Type type = ckToCheck.GetType();
if (type.Name.ToLower() == “string“)
{
ckName = (string)ckToCheck;
}
else if (type.Name == “Cookie“)
{
ckName = ((Cookie)ckToCheck).Name;
}
if (ckName != ““)
{
type = cookies.GetType();
// is single Cookie
if (type.Name == “Cookie“)
{
if (ckName == ((Cookie)cookies).Name)
{
isContain = true;
}
}
// is CookieCollection
else if (type.Name == “CookieCollection“)
{
foreach (Cookie ck in (CookieCollection)cookies)
{
if (ckName == ck.Name)
{
isContain = true;
break;
}
}
}
// is single cookie name string
else if (type.Name.ToLower() == “string“)
{
if (ckName == (string)cookies)
{
isContain = true;
}
}
// is cookie name string[]
else if (type.Name.ToLower() == “string[]“)
{
foreach (string name in ((string[])cookies))
{
if (ckName == name)
{
isContain = true;
break;
}
}
}
}
}
return isContain;
}//isContainCookie
public void addCookieToCookies(Cookie toAdd ref CookieCollection cookies bool overwriteDomain)
{
bool found = false;
if (cookies.Count > 0)
{
foreach (Cookie originalCookie in cookies)
{
if (ori
- 上一篇:c#获取本机打印机列表
- 下一篇:spam_train.csv
评论
共有 条评论