Ejemplo n.º 1
0
        public void Test_HttpOption_FromRawText()
        {
            string text = @"
POST http://www.fish-web-demo.com/api/ns/TestAutoAction/submit.aspx HTTP/1.1
Host: www.fish-web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestAutoFindAction.htm
Content-Length: 72
Cookie: hasplmlang=_int_; LoginBy=productKey; PageStyle=Style2;
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

input=Fish+Li&Base64=%E8%BD%AC%E6%8D%A2%E6%88%90Base64%E7%BC%96%E7%A0%81
";

            HttpOption option = HttpOption.FromRawText(text);

            Assert.AreEqual("http://www.fish-web-demo.com/api/ns/TestAutoAction/submit.aspx", option.GetRequestUrl());
            Assert.AreEqual("input=Fish+Li&Base64=%E8%BD%AC%E6%8D%A2%E6%88%90Base64%E7%BC%96%E7%A0%81", option.GetPostData().ToString());
            Assert.AreEqual("application/x-www-form-urlencoded", option.ContentType);
        }
Ejemplo n.º 2
0
        public void 结合FromRawText和Data发送复杂的HTTP请求()
        {
            // 可以从 Fiddler 抓到所需要请求头,去掉:数据部分
            string request = @"
POST http://www.fish-web-demo.com/test1.aspx HTTP/1.1
Host: www.fish-web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestAutoFindAction.htm
Cookie: hasplmlang=_int_; LoginBy=productKey; PageStyle=Style2;
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
";

            // 1,根据一段长文本 快速设置 URL, method, headers
            HttpOption httpOption = HttpOption.FromRawText(request);

            // 2,设置提交数据与格式
            httpOption.Format = SerializeFormat.Form;
            httpOption.Data   = new { id = 2, name = "aaaa", time = DateTime.Now };

            // 3,发送请求,获取结果
            string result = httpOption.GetResult();
        }
Ejemplo n.º 3
0
        public async Task Test1()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/ajax/ns/TestFile/Download1.aspx HTTP/1.1
Host: www.fish-mvc-demo.com
Connection: keep-alive
Content-Length: 171
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://www.fish-mvc-demo.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174
Content-Type: application/x-www-form-urlencoded
Referer: http://www.fish-mvc-demo.com/Pages/Demo/TestFileDownload.aspx
Accept-Encoding: gzip, deflate, lzma
Accept-Language: zh-CN,zh;q=0.8

filename=%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%E6%97%A0%E4%B9%B1%E7%A0%81%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D%3C%3E%3F%7C.txt&submit=%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6");

            string headerValue = null;

            option.ReadResponseAction = (response) => headerValue = response.Headers["Content-Disposition"];

            string returnText = await option.SendAsync <string>();

            string expected = Guid.Empty.ToString();

            Assert.AreEqual(expected, returnText);
            Assert.IsTrue(System.Web.HttpUtility.UrlDecode(headerValue).IndexOf("中文汉字无乱码") > 0);
        }
Ejemplo n.º 4
0
        public void 根据请求文本发送请求()
        {
            // 下面这段文本,可以从 Fiddler 或者一些浏览器的开发工具中获取
            // 拿到这段文本,不需要做任何处理,直接调用 HttpOption.FromRawText 就可以了,就是这样简单!


            string request = @"
POST http://www.fish-web-demo.com/test1.aspx HTTP/1.1
Host: www.fish-web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestAutoFindAction.htm
Content-Length: 72
Cookie: hasplmlang=_int_; LoginBy=productKey; PageStyle=Style2;
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

input=Fish+Li&Base64=%E8%BD%AC%E6%8D%A2%E6%88%90Base64%E7%BC%96%E7%A0%81
";
            string text    =
                HttpOption.FromRawText(request)     // 构建 HttpOption 实例
                .GetResult();                       // 发送请求
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 用新的URL登录
        /// </summary>
        /// <param name="currentUrl"></param>
        /// <returns></returns>
        private Cookie Login(string currentUrl)
        {
            HttpOption option = HttpOption.FromRawText(_loginRequestRaw);

            Match m = _regex.Match(option.Url);

            if (m.Success == false)
            {
                throw new ArgumentException("登录请求中的URL格式不正确。");
            }

            Match m2 = _regex.Match(currentUrl);

            if (m2.Success == false)
            {
                throw new ArgumentException("当前待发送请求中的URL格式不正确。");
            }

            option.Url    = m2.Groups["host"].Value + m.Groups["path"].Value;
            option.Cookie = new CookieContainer();

            option.Send();

            var    cookies = option.Cookie.GetCookies(new Uri(m2.Groups["host"].Value));
            Cookie cookie  = cookies[_loginCookieName];

            if (cookie == null)
            {
                throw new InvalidOperationException("服务端没有返回指定名称的登录Cookie");
            }

            return(cookie);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据一段请求文本创建WebContext,并填充相关属性,
        /// 文本格式可参考Fiddler的Inspectors标签页内容
        /// </summary>
        /// <param name="requestText"></param>
        /// <returns></returns>
        public static WebContext FromRawText(string requestText)
        {
            HttpOption option = HttpOption.FromRawText(requestText);

            WebContext context = new WebContext(option.Url);

            context.Request.HttpMethod = option.Method;
            //context.Request.Browser=;

            if (option.Headers != null)
            {
                // 填充请求头
                foreach (NameValue nv in option.Headers)
                {
                    context.Request.AddHeader(nv.Name, nv.Value);
                }

                // 获取 UrlReferrer
                string urlReferrer = option.Headers["Referer"];
                if (string.IsNullOrEmpty(urlReferrer) == false)
                {
                    context.Request.UrlReferrer = urlReferrer;
                }

                // 填充 Cookie
                string cookieLine = option.Headers["Cookie"];
                if (string.IsNullOrEmpty(cookieLine) == false)
                {
                    List <NameValue> list = cookieLine.SplitString(';', '=');
                    foreach (NameValue nv in list)
                    {
                        context.Request.AddCookie(new HttpCookie(nv.Name, nv.Value));
                    }
                }


                // 获取浏览器信息
                string userAgent = option.Headers["User-Agent"];
                if (string.IsNullOrEmpty(userAgent) == false)
                {
                    SetBrowserInfo(userAgent, context);
                }

                string contentType = option.Headers["Content-Type"];
                if (string.IsNullOrEmpty(contentType) == false)
                {
                    context.Request.ContentType = contentType;
                }
            }

            // 设置请求体
            if (option.Data != null)
            {
                context.Request.SetForm((string)option.Data);
                context.Request.SetInputStream((string)option.Data);
            }

            return(context);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取一个可用于多次发送的请求参数对象
        /// </summary>
        /// <param name="currentRequestRaw"></param>
        /// <returns></returns>
        private HttpOption GetSendOption(string currentRequestRaw)
        {
            HttpOption option = HttpOption.FromRawText(currentRequestRaw);

            Cookie cookie = Login(option.Url);

            ReplaceLoginCookie(option, cookie);

            return(option);
        }
Ejemplo n.º 8
0
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            if (txtMongoDbConnectionString.Text.Length == 0)
            {
                MessageBox.Show("日志数据库的连接字符串不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtLoginCookieName.Text.Length == 0)
            {
                MessageBox.Show("登录Cookie名称不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtLoginRequestRaw.Text.Length == 0)
            {
                MessageBox.Show("登录请求文本不能为空。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try {
                // 检验输入的请求文本是否正确
                HttpOption option = HttpOption.FromRawText(txtLoginRequestRaw.Text);
                Uri        uri    = new Uri(option.Url);

                if (option.Data == null)
                {
                    throw new ArgumentException("没有登录操作需要的提交数据。");
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            RunTimeSettings settings = new RunTimeSettings();

            settings.MongoDbConnectionString = txtMongoDbConnectionString.Text;
            settings.LoginCookieName         = txtLoginCookieName.Text;
            settings.LoginRequestRaw         = txtLoginRequestRaw.Text;

            XmlHelper.XmlSerializeToFile(settings, "RunTimeSettings.config", Encoding.UTF8);

            MessageBox.Show("保存操作成功完成。", this.FindForm().Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

            EventHandler <SaveSettingsEventArgs> eventHandler = this.SaveSettingButtonClick;

            if (eventHandler != null)
            {
                SaveSettingsEventArgs args = new SaveSettingsEventArgs {
                    NewSettings = settings
                };
                eventHandler(btnCancelSetting, args);
            }
        }
Ejemplo n.º 9
0
        public async Task Test3()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/TestFile/Sum.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded

numbers=1&numbers=2&numbers=3&numbers=4&numbers=5");


            string actual = await option.SendAsync <string>();

            string expected = "15";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public async Task Test_BinaryResult()
        {
            string text = "复制可执行的SQL";

            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/Demo1/TestBinaryResult.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded

s=" + System.Web.HttpUtility.UrlEncode(text));


            byte[] actual = await option.GetResultAsync <byte[]>();

            byte[] expected = Encoding.UTF8.GetBytes(text);
            actual.IsEqual(expected);
        }
Ejemplo n.º 11
0
        private HttpOption CreateHttpOption(RequestInfo request, bool supportWindowsAuth, string userAgent)
        {
            HttpOption option = HttpOption.FromRawText(request.Text);

            option.Headers.Remove("X-Mysoft-Profiler");                 // 移队Fiddler插件中增加的监控头,避免返回无用信息
            option.Headers.Remove("Host");                              // 这个头没什么用,反而可能与网址参数不一样

            if (string.IsNullOrEmpty(userAgent) == false)
            {
                option.Headers.Remove("User-Agent");
                option.Headers.Add("User-Agent", userAgent);
            }

            if (supportWindowsAuth)                     // 支持Windows身份认证
            {
                option.Credentials = CredentialCache.DefaultCredentials;
            }

            // 重新计算请求地址
            if (string.IsNullOrEmpty(_currentExecuteInfo.TargetSite) == false)
            {
                option.Url
                      = request.RealUrl
                      = _currentExecuteInfo.TargetSite + request.RelativeUrl;


                string referer = option.Headers["Referer"];
                if (string.IsNullOrEmpty(referer) == false)
                {
                    referer = referer.Replace(request.SiteRoot, _currentExecuteInfo.TargetSite);
                    option.Headers.Remove("Referer");
                    option.Headers.Add("Referer", referer);
                }
            }
            else
            {
                request.RealUrl = request.SiteRoot + request.RelativeUrl;
            }


            return(option);
        }
Ejemplo n.º 12
0
        public async Task Test2()
        {
            HttpOption option = HttpOption.FromRawText(@"
GET http://www.fish-mvc-demo.com/file-download/demo1/%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%E6%97%A0%E4%B9%B1%E7%A0%81~!%40%23%24%25%5E%26*()_%2B-%3D%3C%3E%3F%7C.txt HTTP/1.1
Host: www.fish-mvc-demo.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174
Referer: http://www.fish-mvc-demo.com/Pages/Demo/TestFileDownload.aspx
Accept-Encoding: gzip, deflate, lzma, sdch
Accept-Language: zh-CN,zh;q=0.8

");

            string actual = await option.SendAsync <string>();

            string expected = Guid.Empty.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public async Task Test1()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestGuid2.aspx HTTP/1.1

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            // Action 要求以 PUT 方式提交,所以应该是404错误。

            int stateCode = await option.GetStatusCode();

            Assert.AreEqual(404, stateCode);


            option = HttpOption.FromRawText(@"
PUT http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestGuid2.aspx HTTP/1.1

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            string actual = await option.SendAsync <string>();

            string expected = "8679b2c7-75e5-47b7-86db-aa60addc10ab";

            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestContextDataAttribute.aspx HTTP/1.1
User-Agent: Hello-Fish

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            actual = await option.SendAsync <string>();

            expected = "Hello-Fish";
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void Test1()
        {
            HttpOption option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetXml.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 1
");

            string xmlResult = option.Send <string>();
            string expected  = "</TestSerializerModel>";

            Assert.IsTrue(xmlResult.EndsWith(expected));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test1_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 2

" + xmlResult);

            string actual = option.Send <string>();

            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test2_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Content-Length: 387
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 3

" + xmlResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetJson.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Cookie: PageStyle=Style2
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 4
");

            string jsonResult = option.Send <string>();

            Assert.IsTrue(jsonResult.StartsWith("{") && jsonResult.EndsWith("}"));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test1_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 5

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test2_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 6

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetXml2.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 7

");

            xmlResult = option.Send <string>();
            expected  = "</TestSerializerModel2>";
            Assert.IsTrue(xmlResult.EndsWith(expected));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test3_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 8

" + xmlResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test4_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 9

" + xmlResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetJson2.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 10
");

            jsonResult = option.Send <string>();
            Assert.IsTrue(jsonResult.StartsWith("{") && jsonResult.EndsWith("}"));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test3_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 11

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test4_AutoCheck.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 12

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetXml5.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 13

");

            xmlResult = option.Send <string>();
            expected  = "</TestSerializerModel3>";
            Assert.IsTrue(xmlResult.EndsWith(expected));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test5.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 14

" + xmlResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test6.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/xml; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 15

" + xmlResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
GET http://www.fish-web-demo.com/api/ns/TestSerializer/GetJson5.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: null; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 16
");

            jsonResult = option.Send <string>();
            Assert.IsTrue(jsonResult.StartsWith("{") && jsonResult.EndsWith("}"));



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test5.aspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 17

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-web-demo.com/api/ns/TestSerializer/Test6.caspx HTTP/1.1
Host: www.fish-ClownFish.Web-demo.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/plain, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://www.fish-web-demo.com/Pages/Demo/TestSerializer.htm
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
test: 18

" + jsonResult);

            actual   = option.Send <string>();
            expected = "1";
            Assert.AreEqual(expected, actual);
        }