Exemple #1
0
        public void MultipartEncoding()
        {
            var encoding = Encoding.GetEncoding(1251);
            var part     = new NFX.Web.Multipart.Part("field");

            part.Content = "Значение";

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

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

            req.Method          = "POST";
            req.ContentType     = NFX.Web.ContentType.FORM_MULTIPART_ENCODED + "; charset=windows-1251";
            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);

                Assert.AreEqual(part.Content.AsString(), encoding.GetString(ms.ToArray()));
            }
        }
Exemple #2
0
        private void MultipartTest(string type)
        {
            var partField = new NFX.Web.Multipart.Part("field");

            partField.Content = "value";

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

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

            var partBinFile = new NFX.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 NFX.Web.Multipart(new NFX.Web.Multipart.Part[] { partField, partTxtFile, partBinFile });

            var enc = mp.Encode();

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

            req.Method          = "POST";
            req.ContentType     = NFX.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;
                Assert.AreEqual(partField.Content.AsString(), Encoding.UTF8.GetString(returned.Take(fieldSize).ToArray()));
                Assert.AreEqual(partTxtFile.Content.AsString(), Encoding.UTF8.GetString(returned.Skip(fieldSize).Take(txtFileSize).ToArray()));
                Assert.IsTrue(NFX.IOMiscUtils.MemBufferEquals(partBinFile.Content as byte[], returned.Skip(fieldSize + txtFileSize).ToArray()));
            }
        }
Exemple #3
0
        private void MultipartTest(string type)
        {
            var partField = new NFX.Web.Multipart.Part("field");
              partField.Content = "value";

              var partTxtFile = new NFX.Web.Multipart.Part("text");
              partTxtFile.Content = "Text with\r\nnewline";
              partTxtFile.FileName = "TxtFile";
              partTxtFile.ContentType = "Content-type: text/plain";

              var partBinFile = new NFX.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 NFX.Web.Multipart(new NFX.Web.Multipart.Part[] { partField, partTxtFile, partBinFile });

              var enc = mp.Encode();

              var req = HttpWebRequest.CreateHttp(INTEGRATION_HTTP_ADDR + type);
              req.Method = "POST";
              req.ContentType = NFX.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;
            Assert.AreEqual(partField.Content.AsString(), Encoding.UTF8.GetString(returned.Take(fieldSize).ToArray()));
            Assert.AreEqual(partTxtFile.Content.AsString(), Encoding.UTF8.GetString(returned.Skip(fieldSize).Take(txtFileSize).ToArray()));
            Assert.IsTrue(NFX.IOMiscUtils.MemBufferEquals(partBinFile.Content as byte[], returned.Skip(fieldSize + txtFileSize).ToArray()));
              }
        }
Exemple #4
0
        public void MultipartEncoding()
        {
            var encoding = Encoding.GetEncoding(1251);
              var part = new NFX.Web.Multipart.Part("field");
              part.Content = "Значение";

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

              var req = HttpWebRequest.CreateHttp(INTEGRATION_HTTP_ADDR + "MultipartEncoding");
              req.Method = "POST";
              req.ContentType = NFX.Web.ContentType.FORM_MULTIPART_ENCODED + "; charset=windows-1251";
              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);

            Assert.AreEqual(part.Content.AsString(), encoding.GetString(ms.ToArray()));
              }
        }