UrlEncode() public static méthode

Url을 Encoding한다. 특히 인자가 한글인 경우 문자열이 깨지기 쉽고, 연결자 (?, &) 등과 겹쳐서 다른 문자로 해석되어 질 수 있다. 이를 방지하기 위해 위의 문자들을 제거하여 작업을 수행한다.
public static UrlEncode ( string payload, Encoding enc = null ) : string
payload string 인코딩할 문자열
enc System.Text.Encoding 인코딩 방식
Résultat string
Exemple #1
0
        public void HttpGet()
        {
            foreach (string script in ScriptPaths)
            {
                var http = new HttpClient(script + "?" + HtmlTool.UrlEncode(PayLoad));

                var result = http.Get();
                Assert.IsNotEmpty(result, "Result is Empty. script=" + script);

                if (IsDebugEnabled)
                {
                    log.Debug(result.EllipsisChar(80));
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("============================");
            }

            foreach (string script in ScriptPaths)
            {
                var httpUtf8 = new HttpClient(script + "?" + HtmlTool.UrlEncode(PayLoad, Encoding.UTF8));

                var result = httpUtf8.Get();
                Assert.IsNotEmpty(result, "Result is Empty. script=" + script);

                if (IsDebugEnabled)
                {
                    log.Debug(result.EllipsisChar(80));
                }
            }
        }
Exemple #2
0
        public void HttpEncoding()
        {
            string encoded = HtmlTool.UrlEncode(PayLoad, Encoding.UTF8);

            Assert.IsNotEmpty(encoded);
            Assert.AreNotEqual(PayLoad, encoded);

            if (IsDebugEnabled)
            {
                log.Debug("Payload=" + PayLoad);
                log.Debug("Encoded Payload=" + encoded);
            }
        }
Exemple #3
0
        public void DownloadData()
        {
            var http = new HttpClient(Echo1 + "?" + HtmlTool.UrlEncode(PayLoad, Encoding.UTF8));

            var data = http.DownloadData();

            Assert.IsNotNull(data);
            Assert.Greater(data.Length, 0);

            if (IsDebugEnabled)
            {
                log.Debug("Response = " + Encoding.UTF8.GetString(data).EllipsisChar(80));
            }
        }
Exemple #4
0
        public void HttpGet2()
        {
            var http   = new HttpClient(Echo2 + "?" + HtmlTool.UrlEncode(PayLoad));
            var result = http.Get();

            Assert.IsNotEmpty(result);
            if (IsDebugEnabled)
            {
                log.Debug(result.EllipsisChar(80));
            }

            http = new HttpClient(Echo1 + "?" + HtmlTool.UrlEncode(PayLoad, Encoding.UTF8));

            result = http.Get();
            Assert.IsNotEmpty(result, "Script=" + http.BaseUriString);
            if (IsDebugEnabled)
            {
                log.Debug(result.EllipsisChar(80));
            }
        }