主页 > 知识库 > 网络编程 > ASP/.NET >

一个封装好的Asp.Net C# HttpRequest请求类,可以直接拿来用(2)

来源:博客园 作者:李鹏飞 发表于:2012-08-03 08:36  点击:
双击代码全选 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 View Code using System; using System.Collections.Generic; using

双击代码全选
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
View Code 
    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
    
namespace WebRequestAPP
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "www.baidu.com";
            string param = "<request><param1></param1></request>";
            string method="GET";
    
            for (int i = 0; i < 1; i++)//发送多条请求看看会不会有问题。
            {
                var result = HttpUtility.Request(method, url, param, onComplete);
                Console.WriteLine("-------------Result----------------");
                Console.WriteLine(result);
                Console.WriteLine("-------------End----------------");
    
            }
    
          Console.ReadLine();
        }
    
        /// <summary>
        /// 请求完成后要执行的操作
        /// </summary>
        /// <param name="code">Http状态码</param>
        /// <param name="result">返回结果</param>
        public static void onComplete(HttpStatusCode code, string result)
        {
            Console.WriteLine("HttpRequest complete! as follow:");
            Console.WriteLine("HttpStatusCode:" + code);
            Console.WriteLine("HttpRequestResult:" + result);
        }
    
    }
}
 
第一次发帖子,有不完善的地方,还请大家多指教~~~~

有帮助
(0)
0%
没帮助
(5)
100%