コード例 #1
0
        public static void DotestForMyhttp()
        {
            MyWebTool.MyHttp myHttp = new MyWebTool.MyHttp(false, true);
            myHttp.SendData("http://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou1.txt");
            myHttp.SendData("http://pv.sohu.com/cityjson", "ie=utf-8", "GET");
            myHttp.SendData("http://pv.sohu.com/cityjson", "ie=utf-8", "POST");
            myHttp.SendData("http://pv.sohu.com/cityjson", "ie=utf-8", "POST", new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("name", "DotestForMyhttp")
            }, null, null);

            List <MyWebTool.HttpMultipartDate> hml = new List <MyWebTool.HttpMultipartDate>();

            hml.Add(new MyWebTool.HttpMultipartDate("multipart name", "file name", null, false, "test data"));
            hml.Add(new MyWebTool.HttpMultipartDate("multipart name", null, "comtenttype", false, "test data"));

            myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("name", "DotestForMyhttp")
            }, "body data", hml, null, null);
            myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("name", "DotestForMyhttp")
            }, "body data", hml, "a=1&b=2&c=4", null);
            hml.Add(new MyWebTool.HttpMultipartDate("multipart name", "file name", "comtenttype", true, @"D:\shou1.txt"));

            myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("name", "DotestForMyhttp")
            }, "body data", hml, "a=1&b=2&c=4", null);
        }
コード例 #2
0
        public static void RunMyHttpTest()
        {
            for (int m = 0; m < 100; m++)
            {
                Console.ReadLine();
                Console.WriteLine(Environment.TickCount);
                long          l1  = DateTime.Now.Ticks;
                StringBuilder xxb = new StringBuilder("");
                for (int i = 0; i < 100; i++)
                {
                    xxb.Append("123456789abcdefg");
                }
                xxb.ToString();

                long   l2 = DateTime.Now.Ticks;
                string xx = "";
                for (int i = 0; i < 100; i++)
                {
                    xx += "123456789abcdefg";
                }

                long l3 = DateTime.Now.Ticks;
                Console.WriteLine(string.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}", l1, l2, l3, l2 - l1, l3 - l2));
            }
            Console.ReadLine();
            Console.WriteLine(myHttp.SendData("http://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou.txt"));
            Console.WriteLine(myHttp.SendData("http://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou.txt"));
            Console.WriteLine(myHttp.SendData("http://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou.txt"));
            Console.WriteLine(myHttp.SendData("https://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou.txt"));
            Console.WriteLine(myHttp.SendData("https://pv.sohu.com/cityjson?ie=utf-8", null, "POST", null, @"D:\shou.txt"));
            Console.ReadLine();
            Console.WriteLine(myHttp.SendData("http://www.baidu.com", null, "Get", null, @"D:\baidu.txt"));
            Console.ReadLine();
            List <MyWebTool.HttpMultipartDate>    ntds  = new List <MyWebTool.HttpMultipartDate>();
            List <KeyValuePair <string, string> > heads = new List <KeyValuePair <string, string> >();

            heads.Add(new KeyValuePair <string, string>("Hostx", "HttpPostData"));
            heads.Add(new KeyValuePair <string, string>("xxx", "HttpPostData"));

            ntds.Add(new MyWebTool.HttpMultipartDate("name", "filename", null, false, "test data"));
            ntds.Add(new MyWebTool.HttpMultipartDate("name", "filename", "type", false, "test data"));
            ntds.Add(new MyWebTool.HttpMultipartDate(null, null, "type", false, ""));
            ntds.Add(new MyWebTool.HttpMultipartDate(null, null, "type", false, null));
            ntds.Add(new MyWebTool.HttpMultipartDate("name", "filename", null, true, @"C:\Users\administer\Desktop\new 2")); //@"C:\Users\cllq\Desktop\CSV\my.csv"

            Console.WriteLine(myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", null, null, null, null, null));
            Console.WriteLine(myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", null, null, ntds, null, null));
            Console.WriteLine(myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", heads, "body", ntds, "a=1&b=2", Encoding.UTF8));
            Console.ReadLine();
            Console.WriteLine(myHttp.SendData("http://pv.sohu.com/cityjson?ie=utf-8", null, "Get"));
            Console.WriteLine(myHttp.HttpPostData("http://pv.sohu.com/cityjson?ie=utf-8", heads, "body", ntds, "a=1&b=2", Encoding.UTF8));
            Console.ReadLine();
        }