コード例 #1
0
        public async Task CanParseMultiParamsAndFilesData()
        {
            using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(multiParamsAndFilesTestData)))
            {
                MultiPartFormDataParser parser = new MultiPartFormDataParser(ms, Encoding.Default);
                await parser.ParseAsync();

                Assert.AreEqual(parser.Parameters["text"], "textdata");
                Assert.AreEqual(parser.Parameters["username"], "zhang");

                Assert.AreEqual(parser.Files.Count, 2);
                Assert.AreEqual(parser.Files[0].Filename, "first.txt");
                Assert.AreEqual(parser.Files[0].Name, "file");
                Assert.AreEqual(parser.Files[1].Filename, "second.txt");
                Assert.AreEqual(parser.Files[1].Name, "newfile");

                using (var sw1 = new StreamReader(parser.Files[0].Data))
                    using (var sw2 = new StreamReader(parser.Files[1].Data))
                    {
                        string file1Str = sw1.ReadToEnd();
                        string file2Str = sw2.ReadToEnd();

                        Assert.AreEqual(file1Str, "aaaaaaa");
                        Assert.AreEqual(file2Str, "bbbbbbb");
                    }
            }
        }
コード例 #2
0
        public async Task CanParseMultiParamsData()
        {
            using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(multiParamsTestData)))
            {
                MultiPartFormDataParser parser = new MultiPartFormDataParser(ms, Encoding.Default);
                await parser.ParseAsync();

                Assert.AreEqual(parser.Parameters["text"], "textdata");
                Assert.AreEqual(parser.Parameters["username"], "zhang");
            }
        }
コード例 #3
0
        public override async Task <HttpRequestBody> ExecuteAsync(Stream stream, Encoding e)
        {
            MultiPartFormDataParser parser = new MultiPartFormDataParser(stream, e);
            await parser.ParseAsync();

            HttpRequestBody body = new HttpRequestBody();

            body.Properties = parser.Parameters;
            body.Files      = parser.Files;
            return(body);
        }