HTTP

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


HTTP class provides several methods to make HyperText Transfer protocol requests

Methods

Request

Method

Executes http request of given method

Parameters

ПараметрОписание
methodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
urlTarget address of request.
contentSpecifies the content of POST, PUT or PATCH request. For other methods empty string can be used.
contentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
proxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
EncodingSpecifies the encoding to use. Default value is “UTF-8”
respTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
TimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
CookiesCookies for request.
UserAgentSpecifies value for “User-Agent” header.
UseRedirecttrue if redirects should be followed. Default value is true
MaxRedirectCountMaximum count of redirects. Default values is 5
AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
DownloadPathDownload path for file. Default value is null
UseOriginalUrltrue if use original url; otherwise, false.
throwExceptionOnErrorThrow exception if error occurs
cookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
removeDefaultHeaderstrue 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

Executes http request of given method

Parameters

ПараметрОписание
methodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
urlTarget address of request.
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[]).
contentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
proxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
EncodingSpecifies the encoding to use. Default value is “UTF-8”
respTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
TimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
CookiesCookies for request.
UserAgentSpecifies value for “User-Agent” header.
UseRedirecttrue if redirects should be followed. Default value is true
MaxRedirectCountMaximum count of redirects. Default values is 5
AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
DownloadPathDownload path for file. Default value is null
UseOriginalUrltrue if use original url; otherwise, false.
throwExceptionOnErrorThrow exception if error occurs
cookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
removeDefaultHeaderstrue 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

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

Parameters

ПараметрОписание
methodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
urlTarget address of request.
contentSpecifies the content of POST, PUT or PATCH request. For other methods empty string can be used.
contentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
proxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
EncodingSpecifies the encoding to use. Default value is “UTF-8”
respTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
TimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
CookiesCookies for request.
UserAgentSpecifies value for “User-Agent” header.
UseRedirecttrue if redirects should be followed. Default value is true
MaxRedirectCountMaximum count of redirects. Default values is 5
AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
DownloadPathDownload path for file. Default value is null
UseOriginalUrltrue if use original url; otherwise, false.
throwExceptionOnErrorThrow exception if error occurs
cookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
removeDefaultHeaderstrue 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

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

Parameters

ПараметрОписание
methodHTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)
urlTarget address of request.
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[]).
contentPostingTypeMIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded”
proxyProxy string (for example: “socks5://login:pass@8.5.6.7:8080”).
EncodingSpecifies the encoding to use. Default value is “UTF-8”
respTypeSpecifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).
TimeoutRequest timeout in milliseconds. Default values is 30000 (30 seconds).
CookiesCookies for request.
UserAgentSpecifies value for “User-Agent” header.
UseRedirecttrue if redirects should be followed. Default value is true
MaxRedirectCountMaximum count of redirects. Default values is 5
AdditionalHeadersArray of additional headers and values that will be added to request. Default value is null
DownloadPathDownload path for file. Default value is null
UseOriginalUrltrue if use original url; otherwise, false.
throwExceptionOnErrorThrow exception if error occurs
cookieContainerThe object of cookie container. Use a common collection of cookies between browser and http requests.
removeDefaultHeaderstrue 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);