コード例 #1
0
ファイル: WaveTest.cs プロジェクト: azist/azos
        public void MultipartEncoding()
        {
            var encoding = Encoding.GetEncoding("ISO-8859-1");

            var part = new Azos.Web.Multipart.Part("field");

            part.Content = "Value";

            var mp  = new Azos.Web.Multipart(new Azos.Web.Multipart.Part[] { part });
            var enc = mp.Encode(encoding);

            var req = HttpWebRequest.CreateHttp(INTEGRATION_HTTP_ADDR + "MultipartEncoding");

            req.Method          = "POST";
            req.ContentType     = Azos.Web.ContentType.FORM_MULTIPART_ENCODED + "; charset=iso-8859-1";
            req.ContentLength   = enc.Length;
            req.CookieContainer = new CookieContainer();
            req.CookieContainer.Add(S_WAVE_URI, S_WAVE_COOKIE);

            using (var reqs = req.GetRequestStream())
            {
                reqs.Write(enc.Buffer, 0, (int)enc.Length);
                var resp = req.GetResponse();

                var ms = new MemoryStream();
                resp.GetResponseStream().CopyTo(ms);

                Aver.AreEqual(part.Content.AsString(), encoding.GetString(ms.ToArray()));
            }
        }
コード例 #2
0
ファイル: WaveTest.cs プロジェクト: azist/azos
        private void MultipartTest(string type)
        {
            var partField = new Azos.Web.Multipart.Part("field");

            partField.Content = "value";

            var partTxtFile = new Azos.Web.Multipart.Part("text");

            partTxtFile.Content     = "Text with\r\nnewline";
            partTxtFile.FileName    = "TxtFile";
            partTxtFile.ContentType = "Content-type: text/plain";

            var partBinFile = new Azos.Web.Multipart.Part("bin");

            partBinFile.Content     = new byte[] { 0xff, 0xaa, 0x89, 0xde, 0x23, 0x20, 0xff, 0xfe, 0x02 };
            partBinFile.FileName    = "BinFile";
            partBinFile.ContentType = "application/octet-stream";

            var mp = new Azos.Web.Multipart(new Azos.Web.Multipart.Part[] { partField, partTxtFile, partBinFile });

            var enc = mp.Encode();

            var req = HttpWebRequest.CreateHttp(INTEGRATION_HTTP_ADDR + type);

            req.Method          = "POST";
            req.ContentType     = Azos.Web.ContentType.FORM_MULTIPART_ENCODED;
            req.ContentLength   = enc.Length;
            req.CookieContainer = new CookieContainer();
            req.CookieContainer.Add(S_WAVE_URI, S_WAVE_COOKIE);

            using (var reqs = req.GetRequestStream())
            {
                reqs.Write(enc.Buffer, 0, (int)enc.Length);
                var resp = req.GetResponse();

                var ms = new MemoryStream();
                resp.GetResponseStream().CopyTo(ms);
                var returned = ms.ToArray();

                var fieldSize   = Encoding.UTF8.GetBytes(partField.Content.AsString()).Length;
                var txtFileSize = Encoding.UTF8.GetBytes(partTxtFile.Content.AsString()).Length;
                Aver.AreEqual(partField.Content.AsString(), Encoding.UTF8.GetString(returned.Take(fieldSize).ToArray()));
                Aver.AreEqual(partTxtFile.Content.AsString(), Encoding.UTF8.GetString(returned.Skip(fieldSize).Take(txtFileSize).ToArray()));
                Aver.IsTrue(Azos.IOUtils.MemBufferEquals(partBinFile.Content as byte[], returned.Skip(fieldSize + txtFileSize).ToArray()));
            }
        }