资源简介
我们知道, .Net类库里提供了HttpWebRequest等类,方便我们编程与Web服务器进行交互. 但是实际使用中我们经常会遇到以下需求
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
namespace Deerchao.Utility
{
public class HttpClient
{
#region fields
private bool keepContext;
private string defaultLanguage = “zh-CN“;
private Encoding defaultEncoding = Encoding.UTF8;
private string accept = “*/*“;
private string userAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)“;
private HttpVerb verb = HttpVerb.GET;
private HttpClientContext context;
private readonly List files = new List();
private readonly Dictionary postingData = new Dictionary();
private string url;
private WebHeaderCollection responseHeaders;
private int startPoint;
private int endPoint;
#endregion
#region events
public event EventHandler StatusUpdate;
private void OnStatusUpdate(StatusUpdateEventArgs e)
{
EventHandler temp = StatusUpdate;
if (temp != null)
temp(this e);
}
#endregion
#region properties
///
/// 是否自动在不同的请求间保留Cookie Referer
///
public bool KeepContext
{
get { return keepContext; }
set { keepContext = value; }
}
///
/// 期望的回应的语言
///
public string DefaultLanguage
{
get { return defaultLanguage; }
set { defaultLanguage = value; }
}
///
/// GetString()如果不能从HTTP头或meta标签中获取编码信息则使用此编码来获取字符串
///
public Encoding DefaultEncoding
{
get { return defaultEncoding; }
set { defaultEncoding = value; }
}
///
/// 指示发出Get请求还是Post请求
///
public HttpVerb Verb
{
get { return verb; }
set { verb = value; }
}
///
/// 要上传的文件.如果不为空则自动转为Post请求
///
public List Files
{
get { return files; }
}
///
/// 要发送的Form表单信息
///
public Dictionary PostingData
{
get { return postingData; }
}
///
/// 获取或设置请求资源的地址
///
public string Url
{
get { return url; }
set { url = value; }
}
///
/// 用于在获取回应后暂时记录回应的HTTP头
///
public WebHeaderCollection ResponseHeaders
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 21058 2007-08-11 18:27 HttpClient.cs
- 上一篇:Torrent.cs
- 下一篇:C#员工信息管理系统 SQL数据库
评论
共有 条评论