HTTP

Assembly: ZennoLab.CommandCenter
Full name: ZennoLab.CommandCenter.ZennoPoster.HTTP
Kind: abstract


HTTP class provides several methods to make HyperText Transfer protocol requests

Methods

Request

Method

string Request(HttpMethod method, string url, string content, string contentPostingType, string proxy, string Encoding, ResponceType respType, int Timeout, string Cookies, string UserAgent, bool UseRedirect, int MaxRedirectCount, String[] AdditionalHeaders, string DownloadPath, bool UseOriginalUrl, bool throwExceptionOnError, ICookieContainer cookieContainer, bool removeDefaultHeaders)

Executes http request of given method

Parameters

TypeNameDescription
HttpMethodmethodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
stringurlTarget address of request.
stringcontentSpecifies the content of POST, PUT or PATCH request. For other methods empty string can be used.
stringcontentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
stringproxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
stringEncodingSpecifies the encoding to use. Default value is “UTF-8”
ResponceTyperespTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
intTimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
stringCookiesCookies for request.
stringUserAgentSpecifies value for “User-Agent” header.
boolUseRedirecttrue if redirects should be followed. Default value is true
intMaxRedirectCountMaximum count of redirects. Default values is 5
String[]AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
stringDownloadPathDownload path for file. Default value is null
boolUseOriginalUrltrue if use original url; otherwise, false.
boolthrowExceptionOnErrorThrow exception if error occurs
ICookieContainercookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
boolremoveDefaultHeaderstrue if remove default request headers; otherwise, false.

Returns: The result of request.

Example

var response = ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://httpbin.org/get?a=b", respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example2

var response = ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, "https://httpbin.org/post", "Name=Jonathan+Doe&Age=25",  respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example3

// Post file using multipart/form-data as string
            var sb = new StringBuilder();
            var boundary = string.Format("-----------------------------{0}", Macros.TextProcessing.RandomText(14, "s", "0123456789"));
            
            sb.AppendLine(boundary);
            sb.AppendLine("Content-Disposition: form-data; name=\"file\"; filename=\"cat.jpg\"");
            sb.AppendLine("Content-Type: image/jpeg");
            sb.AppendLine();
            sb.AppendLine(Path.Combine(project.Path, "cat.jpg"));
            sb.Append(boundary);
            sb.Append("--");
            
            string postSite = ZennoPoster.HTTP.Request(
                InterfacesLibrary.Enums.Http.HttpMethod.POST,
                @"http://httpbin.org/post",
                content: sb.ToString(),
                contentPostingType: "multipart/form-data; boundary="+boundary,
                proxy: "",
                Encoding: "UTF-8",
                UserAgent: project.Profile.UserAgent,
                respType: ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
                Timeout: 30000,
                UseRedirect: true,
                MaxRedirectCount: 5,
                cookieContainer: project.Profile.CookieContainer
            );
            
            return postSite;

Example4

// Post file using multipart/form-data as byte[]
            var bytes = new byte[0];
            var boundary = string.Format("-----------------------------{0}", Macros.TextProcessing.RandomText(14, "s", "0123456789"));
            using (var ms = new MemoryStream())
            {
                using(var bw = new BinaryWriter(ms, Encoding.UTF8, false))
                {
                    bw.Write(boundary + "\r\n");
                    bw.Write("Content-Disposition: form-data; name=\"file\"; filename=\"cat.jpg\"" + "\r\n");
                    bw.Write("Content-Type: image/jpeg" + "\r\n\r\n");
                    bw.Write(File.ReadAllBytes(project.Path+"cat.jpg"));
                    bw.Write("\r\n");
                    bw.Write(boundary + "--");		
                }
                bytes = ms.ToArray();
            }
            
            string postSite = ZennoPoster.HTTP.Request(
                InterfacesLibrary.Enums.Http.HttpMethod.POST,
                @"http://httpbin.org/post",
                content: bytes,
                contentPostingType: "multipart/form-data; boundary="+boundary,
                proxy: "",
                Encoding: "UTF-8",
                UserAgent: project.Profile.UserAgent,
                respType: ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
                Timeout: 30000,
                UseRedirect: true,
                MaxRedirectCount: 5,
                cookieContainer: project.Profile.CookieContainer
            );
            
            return postSite;

Example5

$response = \ZennoLab\CommandCenter\ZennoPoster\HTTP::Request(\ZennoLab\InterfacesLibrary\Enums\Http\HttpMethod::GET,"https://www.google.ru/", "","application/x-www-form-urlencoded","", "UTF-8", ZennoLab\InterfacesLibrary\Enums\Http\ResponceType::HeaderAndBody, 30000,"","",FALSE,5,array(),NULL,FALSE,TRUE);

Request

Method

string Request(HttpMethod method, string url, Byte[] content, string contentPostingType, string proxy, string Encoding, ResponceType respType, int Timeout, string Cookies, string UserAgent, bool UseRedirect, int MaxRedirectCount, String[] AdditionalHeaders, string DownloadPath, bool UseOriginalUrl, bool throwExceptionOnError, ICookieContainer cookieContainer, bool removeDefaultHeaders)

Executes http request of given method

Parameters

TypeNameDescription
HttpMethodmethodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
stringurlTarget address of request.
Byte[]contentSpecifies the content of POST, PUT or PATCH request. For other methods use empty array. Null value will cause a compile error, due to type conflict (string and byte[]).
stringcontentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
stringproxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
stringEncodingSpecifies the encoding to use. Default value is “UTF-8”
ResponceTyperespTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
intTimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
stringCookiesCookies for request.
stringUserAgentSpecifies value for “User-Agent” header.
boolUseRedirecttrue if redirects should be followed. Default value is true
intMaxRedirectCountMaximum count of redirects. Default values is 5
String[]AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
stringDownloadPathDownload path for file. Default value is null
boolUseOriginalUrltrue if use original url; otherwise, false.
boolthrowExceptionOnErrorThrow exception if error occurs
ICookieContainercookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
boolremoveDefaultHeaderstrue if remove default request headers; otherwise, false.

Returns: The result of request.

Example

var response = ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://httpbin.org/get?a=b", new byte[0],respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example2

var response = ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, "https://httpbin.org/post", Encoding.UTF8.GetBytes("Name=Jonathan+Doe&Age=25"), respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example3

$response = \ZennoLab\CommandCenter\ZennoPoster\HTTP::Request(\ZennoLab\InterfacesLibrary\Enums\Http\HttpMethod::GET,"https://www.google.ru/", array(),"application/x-www-form-urlencoded","", "UTF-8", ZennoLab\InterfacesLibrary\Enums\Http\ResponceType::HeaderAndBody, 30000,"","",FALSE,5,array(),NULL,FALSE,TRUE);

RequestBytes

Method

Byte[] RequestBytes(HttpMethod method, string url, string content, string contentPostingType, string proxy, string Encoding, ResponceType respType, int Timeout, string Cookies, string UserAgent, bool UseRedirect, int MaxRedirectCount, String[] AdditionalHeaders, string DownloadPath, bool UseOriginalUrl, bool throwExceptionOnError, ICookieContainer cookieContainer, bool removeDefaultHeaders)

Executes http request of given method and returns response as byte array

Parameters

TypeNameDescription
HttpMethodmethodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
stringurlTarget address of request.
stringcontentSpecifies the content of POST, PUT or PATCH request. For other methods empty string can be used.
stringcontentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
stringproxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
stringEncodingSpecifies the encoding to use. Default value is “UTF-8”
ResponceTyperespTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
intTimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
stringCookiesCookies for request.
stringUserAgentSpecifies value for “User-Agent” header.
boolUseRedirecttrue if redirects should be followed. Default value is true
intMaxRedirectCountMaximum count of redirects. Default values is 5
String[]AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
stringDownloadPathDownload path for file. Default value is null
boolUseOriginalUrltrue if use original url; otherwise, false.
boolthrowExceptionOnErrorThrow exception if error occurs
ICookieContainercookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
boolremoveDefaultHeaderstrue if remove default request headers; otherwise, false.

Returns: The result of request.

Example

var response = ZennoPoster.HTTP.RequestBytes(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://httpbin.org/get?a=b", "",respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example2

var response = ZennoPoster.HTTP.RequestBytes(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, "https://httpbin.org/post", "Name=Jonathan+Doe&Age=25",respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example3

$response = \ZennoLab\CommandCenter\ZennoPoster\HTTP::RequestBytes(\ZennoLab\InterfacesLibrary\Enums\Http\HttpMethod::GET,"https://www.google.ru/", "","application/x-www-form-urlencoded","", "UTF-8", ZennoLab\InterfacesLibrary\Enums\Http\ResponceType::HeaderAndBody, 30000,"","",FALSE,5,array(),NULL,FALSE,TRUE);

RequestBytes

Method

Byte[] RequestBytes(HttpMethod method, string url, Byte[] content, string contentPostingType, string proxy, string Encoding, ResponceType respType, int Timeout, string Cookies, string UserAgent, bool UseRedirect, int MaxRedirectCount, String[] AdditionalHeaders, string DownloadPath, bool UseOriginalUrl, bool throwExceptionOnError, ICookieContainer cookieContainer, bool removeDefaultHeaders)

Executes http request of given method and returns response as byte array

Parameters

TypeNameDescription
HttpMethodmethodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
stringurlTarget address of request.
Byte[]contentSpecifies the content of POST, PUT or PATCH request. For other methods use empty array. null value will cause a compile error, due to type conflict (string and byte[]).
stringcontentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
stringproxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
stringEncodingSpecifies the encoding to use. Default value is “UTF-8”
ResponceTyperespTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
intTimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
stringCookiesCookies for request.
stringUserAgentSpecifies value for “User-Agent” header.
boolUseRedirecttrue if redirects should be followed. Default value is true
intMaxRedirectCountMaximum count of redirects. Default values is 5
String[]AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
stringDownloadPathDownload path for file. Default value is null
boolUseOriginalUrltrue if use original url; otherwise, false.
boolthrowExceptionOnErrorThrow exception if error occurs
ICookieContainercookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
boolremoveDefaultHeaderstrue if remove default request headers; otherwise, false.

Returns: The result of request.

Example

var response = ZennoPoster.HTTP.RequestBytes(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://httpbin.org/get?a=b", new byte[0],respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example2

var response = ZennoPoster.HTTP.RequestBytes(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, "https://httpbin.org/post", "Name=Jonathan+Doe&Age=25", respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);

Example3

$response = \ZennoLab\CommandCenter\ZennoPoster\HTTP::RequestBytes(\ZennoLab\InterfacesLibrary\Enums\Http\HttpMethod::GET,"https://www.google.ru/", array(),"application/x-www-form-urlencoded","", "UTF-8", ZennoLab\InterfacesLibrary\Enums\Http\ResponceType::HeaderAndBody, 30000,"","",FALSE,5,array(),NULL,FALSE,TRUE);