コード例 #1
0
        public async Task TestPostFormData()
        {
            // Use postman-echo.com to test posting form data including files:
            RestRequest request = new Uri("https://postman-echo.com/post").SendPOST();

            DirectoryEntry dir          = EnvironmentV2.instance.GetNewInMemorySystem();
            FileEntry      fileToUpload = dir.GetChild("test.txt");

            fileToUpload.SaveAsText("I am a text");
            request.AddFileViaForm(fileToUpload);

            string formText = "I am a string";

            request.WithFormContent(new Dictionary <string, object>()
            {
                { "formString1", formText }
            });

            PostmanEchoResponse result = await request.GetResult <PostmanEchoResponse>();

            Log.d(JsonWriter.AsPrettyString(result));
            Assert.Single(result.form);
            Assert.Equal(formText, result.form.First().Value);
            Assert.Single(result.files);
            Assert.Equal(fileToUpload.Name, result.files.First().Key);
        }
コード例 #2
0
ファイル: FileUploadTests.cs プロジェクト: cs-util-com/cscore
        public async Task TestPostFormData()
        {
            // Use postman-echo.com to test posting form data including files:
            RestRequest request = new Uri("https://postman-echo.com/post").SendPOST();

            DirectoryEntry dir          = EnvironmentV2.instance.GetNewInMemorySystem();
            FileEntry      fileToUpload = dir.GetChild("test.txt");

            fileToUpload.SaveAsText(GenerateLongStringForTextFile());
            request.AddFileViaForm(fileToUpload);
            float progressInPercent = 0;

            request.onProgress = (newProgress) => { progressInPercent = newProgress; };

            string formText = "I am a string";

            request.WithFormContent(new Dictionary <string, object>()
            {
                { "formString1", formText }
            });

            PostmanEchoResponse result = await request.GetResult <PostmanEchoResponse>();

            Log.d(JsonWriter.AsPrettyString(result));
            Assert.Single(result.form);
            Assert.Equal(100, progressInPercent);
            Assert.Equal(formText, result.form.First().Value);
            Assert.Single(result.files);
            Assert.Equal(fileToUpload.Name, result.files.First().Key);
            Assert.True(result.headers.contentType.StartsWith("multipart/form-data"));
        }