一聚教程网:一个值得你收藏的教程网站

热门教程

C# 刚写的 HttpRequsetResponse 类,异步、事件... 还热乎着呢!

时间:2022-07-02 12:04:16 编辑:袖梨 来源:一聚教程网

//调用示例:
private void button1_Click(object sender, System.EventArgs e)
{
    HttpRequestResponse xx = new HttpRequestResponse();
    xx.DataArrival += new DataArrivalEventHandler(xx_DataArrival);
    xx.SendRequest("http://www.triaton.com.cn/dotnet/tree/index.asp","userid=老","Post");
    xx.SendRequest("http://www.triaton.com.cn/dotnet/tree/index.asp","userid=老","get");
}
private void xx_DataArrival(object sender, DataArrivalEventArgs e)
{
    Console.WriteLine(e.RecievedData);
    Console.WriteLine(e.IsComplete);
}
//========================
//Class1.cs
using System;
using System.Net;
using System.Threading;
using System.Text;
using System.IO;
public class RequestState
{
    const int BUFFER_SIZE = 1024;
    public System.Text.StringBuilder RequestData;
    public byte[] BufferRead;
    public System.Net.HttpWebRequest Request;
    public System.IO.Stream ResponseStream;
    public System.Text.Decoder StreamDecode = System.Text.Encoding.GetEncoding("gb2312").GetDecoder();
    
    public RequestState()
    {
        BufferRead = new byte[BUFFER_SIZE];

热门栏目