資源簡介
接收發(fā)送HTTP協(xié)議報文數(shù)據(jù),非常不錯的源代碼
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
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;
namespace?HTTP
{
????///
????///上傳事件委托
????///
????///
????///
????public?delegate?void?WebClientUploadEvent(object?sender?HTTP.UploadEventArgs?e);
????///
????///下載事件委托
????///
????///
????///
????public?delegate?void?WebClientDownloadEvent(object?sender?HTTP.DownloadEventArgs?e);
????///
????///上傳事件參數(shù)
????///
????public?struct?UploadEventArgs
????{
????????///
????????///上傳數(shù)據(jù)總大小
????????///
????????public?long?totalBytes;
????????///
????????///已發(fā)數(shù)據(jù)大小
????????///
????????public?long?bytesSent;
????????///
????????///發(fā)送進度(0-1)
????????///
????????public?double?sendProgress;
????????///
????????///發(fā)送速度Bytes/s
????????///
????????public?double?sendSpeed;
????}
????///
????///下載事件參數(shù)
????///
????public?struct?DownloadEventArgs
????{
????????///
????????///下載數(shù)據(jù)總大小
????????///
????????public?long?totalBytes;
????????///
????????///已接收數(shù)據(jù)大小
????????///
????????public?long?bytesReceived;
????????///
????????///接收數(shù)據(jù)進度(0-1)
????????///
????????public?double?ReceiveProgress;
????????///
????????///當前緩沖區(qū)數(shù)據(jù)
????????///
????????public?byte[]?receivedBuffer;
????????///
????????///接收速度Bytes/s
????????///
????????public?double?receiveSpeed;
????}
????///
????///實現(xiàn)向WEB服務器發(fā)送和接收數(shù)據(jù)
????///
????public?class?WebClient
????{
????????private?WebHeaderCollection?requestHeaders?responseHeaders;
????????private?TcpClient?clientSocket;
????????private?MemoryStream?postStream;
????????private?Encoding?encoding?=?Encoding.Default;
????????private?const?string?BOUNDARY?=?“--HEDAODE--“;
????????private?const?int?SEND_BUFFER_SIZE?=?10245;
????????private?const?int?RECEIVE_BUFFER_SIZE?=?10245;
????????private?string?cookie?=?““;
????????private?string?respHtml?=?““;
????????private?string?strRequestHeaders?=?““;
????????private?string?strResponseHeaders?=?““;
????????private?int?statusCode?=?0;
????????private?bool?isCanceled?=?false;
????????public?event?WebClientUploadEvent?UploadProgressChanged;
????????public?event?WebClientDownloadEvent?DownloadProgressChanged;
????????///
????????///初始化WebClient類
????????///
????????public?WebClient()
????????{
????????????responseHeaders?=?new?WebHeaderCollection();
????????????requestHeaders?=?new?WebHeaderCollection();
????????}
????
評論
共有 條評論