• 大小: 25KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: C#
  • 标签: HTTP  

资源简介

接收发送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();
        }
    

评论

共有 条评论