.Net helper library which facilitates creation of a web POST request body.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
PostRequestFactory.Core
PostRequestFactory.TestConsole
PostRequestFactory.UnitTests
.gitignore
LICENSE.txt
PostRequestFactory.1.0.1.nupkg
PostRequestFactory.sln
README.md

README.md

PostRequestFactory

This is a.Net library which facilitates manually creation of a web request body. Generated web request body structure respects all the standards specified in HTML FORMS. With PostRequestFactory you can generate web request body of application/x-www-form-urlencoded and multipart/form-data content types.

PostRequestFactory was created by using .Net Framework 4.0 .

Basically for being able to access functionalities provided by this library you should use RequestFactory class which exposes a static method CreateRequest that will return an instance of the PostRequest class which contains all the data about web request. A PostRequest is build based on the provided parameters which can be of the following types:

  • BasicRequestParameter - used only for application/x-www-form-urlencoded content types
  • TextRequestParameter - used only for multipart/form-data content types and it can be mixed with BinaryRequestParameter
  • BinaryRequestParameter - used only for multipart/form-data content types, used for larger binary data transport

Usage flow is the following: You should encapsulate web request data into corresponding request parameters and based on these parameters will be generated a web request, content of which you can use in various forms.

NuGet

You can add this library to your project by using NuGet, you just have to type in your Package Manager Console:

Install-Package PostRequestFactory

Usage examples (C#)

  • Creates an application/x-www-form-urlencoded web request
            var paramList =
                new List<IRequestParameter>
                    {
                        new BasicRequestParameter("value", "xxxȘȘȘșșaaaȚȚȚbbbÎÎ"),
                        new BasicRequestParameter("value2", "AbcȘaBc")
                    };

            var request = RequestFactory.CreateRequest(paramList);

            webClient.Headers.Add("Content-Type", request.ContentTypeHeader);

            var response = webClient.UploadData("http://TestUrl/TestAction", request.BodyAsBytes);
  • Creates a multipart/form-data web request
           webClient = new WebClient();

            paramList =
                new List<IRequestParameter>
                    {
                        //this parameter's content will be transported as base64
                        new TextRequestParameter("value", "xxxȘȘȘșșaaaȚȚȚbbbÎÎ",true, Encoding.UTF8),
                        new TextRequestParameter("value2", "cccĂĂĂ")
                    };

            request = RequestFactory.CreateRequest(paramList);

            webClient.Headers.Add("Content-Type", request.ContentTypeHeader);

            response = webClient.UploadData("http://TestUrl/TestAction", request.BodyAsBytes);
  • Creates a multipart/form-data web request by sending a bigger quantity of binary information
           webClient = new WebClient();

            paramList =
                new List<IRequestParameter>
                    {
                        new BinaryRequestParameter("value", "xxxȘȘȘșșaaaȚȚȚbbbÎÎ"),
                        new BinaryRequestParameter("value2", "cccĂĂĂ"),
                        new BinaryRequestParameter("value3",File.ReadAllBytes("BigFile.data"),"BigFile.data")
                    };

            request = RequestFactory.CreateRequest(paramList);

            webClient.Headers.Add("Content-Type", request.ContentTypeHeader);

            response = webClient.UploadData("http://TestUrl/TestAction", request.BodyAsBytes);