資源簡介
接收發送HTTP協議報文數據,非常不錯的源代碼
代碼片段和文件信息
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);
????///
????///上傳事件參數
????///
????public?struct?UploadEventArgs
????{
????????///
????????///上傳數據總大小
????????///
????????public?long?totalBytes;
????????///
????????///已發數據大小
????????///
????????public?long?bytesSent;
????????///
????????///發送進度(0-1)
????????///
????????public?double?sendProgress;
????????///
????????///發送速度Bytes/s
????????///
????????public?double?sendSpeed;
????}
????///
????///下載事件參數
????///
????public?struct?DownloadEventArgs
????{
????????///
????????///下載數據總大小
????????///
????????public?long?totalBytes;
????????///
????????///已接收數據大小
????????///
????????public?long?bytesReceived;
????????///
????????///接收數據進度(0-1)
????????///
????????public?double?ReceiveProgress;
????????///
????????///當前緩沖區數據
????????///
????????public?byte[]?receivedBuffer;
????????///
????????///接收速度Bytes/s
????????///
????????public?double?receiveSpeed;
????}
????///
????///實現向WEB服務器發送和接收數據
????///
????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();
????????}
????
評論
共有 條評論