Beispiel #1
0
        public void GET数组参数测试()
        {
            var www = new Httpdoer("www.baidu.com");

            www.Method = HttpRequestMethod.Get;
            www.Params.AddModel(new { a = new[] { 1, 2, 3 } });
            www.Query.ArrayEncodeMode = ArrayEncodeMode.Default;
            Assert.AreEqual("http://www.baidu.com?a=1&a=2&a=3", www.ToString("q"));
            www.Query.ArrayEncodeMode = ArrayEncodeMode.Asp;
            Assert.AreEqual("http://www.baidu.com?a[0]=1&a[1]=2&a[2]=3", Uri.UnescapeDataString(www.ToString("q")));
            www.Query.ArrayEncodeMode = ArrayEncodeMode.JQuery;
            Assert.AreEqual("http://www.baidu.com?a[]=1&a[]=2&a[]=3", Uri.UnescapeDataString(www.ToString("q")));
            www.Query.ArrayEncodeMode = ArrayEncodeMode.Json;
            Assert.AreEqual("http://www.baidu.com?a=" + Uri.EscapeDataString("[1,2,3]"), www.ToString("q"));
            www.Query.ArrayEncodeMode = ArrayEncodeMode.Merge;
            Assert.AreEqual("http://www.baidu.com?a=1,2,3", www.ToString("q"));
        }
Beispiel #2
0
        public void 测试生成Url()
        {
            var www = new Httpdoer("www.baidu.com");

            www.Path = "s";
            Assert.AreEqual("http://www.baidu.com/s", www.ToString("q"));


            www.Path = "/s";
            Assert.AreEqual("http://www.baidu.com/s", www.ToString("q"));

            www.Query.Add("id", "1");
            Assert.AreEqual("http://www.baidu.com/s?id=1", www.ToString("q"));

            www.Path = "/s/";
            Assert.AreEqual("http://www.baidu.com/s/?id=1", www.ToString("q"));


            www.Path = "/s/?id=2";
            Assert.AreEqual("http://www.baidu.com/s/?id=2&id=1", www.ToString("q"));

            www      = new Httpdoer("www.baidu.com?id=3");
            www.Path = "s?id=2";
            Assert.AreEqual("http://www.baidu.com/s?id=2", www.ToString("q"));

            www.Query.Add("id", "1");
            Assert.AreEqual("http://www.baidu.com/s?id=2&id=1", www.ToString("q"));

            www.Path = "?id=2";
            Assert.AreEqual("http://www.baidu.com/?id=2&id=1", www.ToString("q"));

            www.Path = "&id=2";
            Assert.AreEqual("http://www.baidu.com/?id=3&id=2&id=1", www.ToString("q"));

            www      = new Httpdoer("www.baidu.com/a?id=3");
            www.Path = "s?id=2";
            Assert.AreEqual("http://www.baidu.com/s?id=2", www.ToString("q"));

            www      = new Httpdoer("www.baidu.com/a/b");
            www.Path = "c";
            Assert.AreEqual("http://www.baidu.com/a/c", www.ToString("q"));
        }
Beispiel #3
0
        public void 测试Path参数()
        {
            var www = new Httpdoer("http://www.baidu.com/{id}");

            www.Params["id"] = 123;
            var url = www.ToString("q");

            Assert.AreEqual("http://www.baidu.com/123", url);

            www = new Httpdoer("http://www.baidu.com/{id}");
            www.Params["id"] = 123;
            www.Params.Add("id", "456");
            url = www.ToString("q");
            Assert.AreEqual("http://www.baidu.com/123,456", url);
        }
Beispiel #4
0
        public void GET对象参数测试()
        {
            var www = new Httpdoer("www.baidu.com");

            www.Method = HttpRequestMethod.Get;
            www.Params.AddModel(new { user = new { id = 1, name = "blqw", sex = true } });
            www.Query.ObjectEncodeMode = ObjectEncodeMode.Default;
            Assert.AreEqual("http://www.baidu.com?user.id=1&user.name=blqw&user.sex=true", www.ToString("q"));
            www.Query.ObjectEncodeMode = ObjectEncodeMode.JQuery;
            Assert.AreEqual("http://www.baidu.com?user[id]=1&user[name]=blqw&user[sex]=true", Uri.UnescapeDataString(www.ToString("q")));
            www.Query.ObjectEncodeMode = ObjectEncodeMode.Json;
            Assert.AreEqual("http://www.baidu.com?user="******"{\"id\":1,\"name\":\"blqw\",\"sex\":true}"), www.ToString("q"));
            www.Query.ObjectEncodeMode = ObjectEncodeMode.NameOnly;
            Assert.AreEqual("http://www.baidu.com?id=1&name=blqw&sex=true", www.ToString("q"));
        }