内容发布更新时间 : 2025/1/5 8:00:35星期一 下面是文章的全部内容请认真阅读。
C#实现http协议通讯类WebClient
CS代码 using System; using
System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.Collections; using System.IO; using System.Text.RegularExpressions; using RE = System.Text.RegularExpressions.Regex; using System.Security.Cryptography.X509Certificates; /*************************************************************************************************************************************************** * *文件名:HttpProc.cs * *创建人:kenter * *日 期:2010.02.23 修改 * *描 述:实现HTTP协议中的GET、POST请求 * *使 用:HttpProc.WebClient client = new HttpProc.WebClient(); client.Encoding = System.Text.Encoding.Default;//默认编码方式,根据需要设置其他类型
client.OpenRead(\普通get请求 MessageBox.Show(client.RespHtml);//获取返回的网页源代码
client.DownloadFile(\album.rar\下载文件
client.OpenRead(\ame=zhangsan&password=123456\提交表单,此处是登录百度的示例
client.UploadFile(\@\上传文件
client.UploadFile(\\//提交含文本域和文件域的表单
*****************************************************************************************************************************************************/ namespace HttpProc
{ ///<summary> ///上传事件委托 ///</summary> ///<param
name=\ ///<param name=\ public delegate void WebClientUploadEvent(object sender,
HttpProc.UploadEventArgs e); ///<summary> ///下载事件委托 ///</summary> ///<param name=\ ///<param name=\ public delegate void WebClientDownloadEvent(object sender, HttpProc.DownloadEventArgs e);
///<summary> ///上传事件参数
///</summary> public struct UploadEventArgs { ///<summary> ///上传数据总大小 ///</summary> public long totalBytes; ///<summary> ///已发数据大小 ///</summary> public long bytesSent; ///<summary> ///发送进度(0-1) ///</summary>
public double sendProgress; ///<summary> ///发送速度Bytes/s ///</summary> public double sendSpeed; } ///<summary> ///下载事件参数 ///</summary> public struct
DownloadEventArgs { ///<summary> ///下载数据总大小 ///</summary> public long totalBytes; ///<summary> ///已接收数据大小 ///</summary> public long bytesReceived; ///<summary> ///接收数据进度(0-1) ///</summary> public double ReceiveProgress;
///<summary> ///当前缓冲区数据
///</summary> public byte[] receivedBuffer;