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
| Type | Name | Description |
|---|---|---|
HttpMethod | method | HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH) |
string | url | Target address of request. |
string | content | Specifies the content of POST, PUT or PATCH request. For other methods empty string can be used. |
string | contentPostingType | MIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded” |
string | proxy | Proxy string (for example: “socks5://login:pass@8.5.6.7:8080”). |
string | Encoding | Specifies the encoding to use. Default value is “UTF-8” |
ResponceType | respType | Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders). |
int | Timeout | Request timeout in milliseconds. Default values is 30000 (30 seconds). |
string | Cookies | Cookies for request. |
string | UserAgent | Specifies value for “User-Agent” header. |
bool | UseRedirect | true if redirects should be followed. Default value is true |
int | MaxRedirectCount | Maximum count of redirects. Default values is 5 |
String[] | AdditionalHeaders | Array of additional headers and values that will be added to request. Default value is null |
string | DownloadPath | Download path for file. Default value is null |
bool | UseOriginalUrl | true if use original url; otherwise, false. |
bool | throwExceptionOnError | Throw exception if error occurs |
ICookieContainer | cookieContainer | The object of cookie container. Use a common collection of cookies between browser and http requests. |
bool | removeDefaultHeaders | true 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
| Type | Name | Description |
|---|---|---|
HttpMethod | method | HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH) |
string | url | Target address of request. |
Byte[] | content | Specifies 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[]). |
string | contentPostingType | MIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded” |
string | proxy | Proxy string (for example: “socks5://login:pass@8.5.6.7:8080”). |
string | Encoding | Specifies the encoding to use. Default value is “UTF-8” |
ResponceType | respType | Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders). |
int | Timeout | Request timeout in milliseconds. Default values is 30000 (30 seconds). |
string | Cookies | Cookies for request. |
string | UserAgent | Specifies value for “User-Agent” header. |
bool | UseRedirect | true if redirects should be followed. Default value is true |
int | MaxRedirectCount | Maximum count of redirects. Default values is 5 |
String[] | AdditionalHeaders | Array of additional headers and values that will be added to request. Default value is null |
string | DownloadPath | Download path for file. Default value is null |
bool | UseOriginalUrl | true if use original url; otherwise, false. |
bool | throwExceptionOnError | Throw exception if error occurs |
ICookieContainer | cookieContainer | The object of cookie container. Use a common collection of cookies between browser and http requests. |
bool | removeDefaultHeaders | true 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
| Type | Name | Description |
|---|---|---|
HttpMethod | method | HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH) |
string | url | Target address of request. |
string | content | Specifies the content of POST, PUT or PATCH request. For other methods empty string can be used. |
string | contentPostingType | MIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded” |
string | proxy | Proxy string (for example: “socks5://login:pass@8.5.6.7:8080”). |
string | Encoding | Specifies the encoding to use. Default value is “UTF-8” |
ResponceType | respType | Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders). |
int | Timeout | Request timeout in milliseconds. Default values is 30000 (30 seconds). |
string | Cookies | Cookies for request. |
string | UserAgent | Specifies value for “User-Agent” header. |
bool | UseRedirect | true if redirects should be followed. Default value is true |
int | MaxRedirectCount | Maximum count of redirects. Default values is 5 |
String[] | AdditionalHeaders | Array of additional headers and values that will be added to request. Default value is null |
string | DownloadPath | Download path for file. Default value is null |
bool | UseOriginalUrl | true if use original url; otherwise, false. |
bool | throwExceptionOnError | Throw exception if error occurs |
ICookieContainer | cookieContainer | The object of cookie container. Use a common collection of cookies between browser and http requests. |
bool | removeDefaultHeaders | true 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
| Type | Name | Description |
|---|---|---|
HttpMethod | method | HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH) |
string | url | Target address of request. |
Byte[] | content | Specifies 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[]). |
string | contentPostingType | MIME type for Value will be set to “Content-Type” header for POST, PUT and PATCH methods. Default value is “application/x-www-form-urlencoded” |
string | proxy | Proxy string (for example: “socks5://login:pass@8.5.6.7:8080”). |
string | Encoding | Specifies the encoding to use. Default value is “UTF-8” |
ResponceType | respType | Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders). |
int | Timeout | Request timeout in milliseconds. Default values is 30000 (30 seconds). |
string | Cookies | Cookies for request. |
string | UserAgent | Specifies value for “User-Agent” header. |
bool | UseRedirect | true if redirects should be followed. Default value is true |
int | MaxRedirectCount | Maximum count of redirects. Default values is 5 |
String[] | AdditionalHeaders | Array of additional headers and values that will be added to request. Default value is null |
string | DownloadPath | Download path for file. Default value is null |
bool | UseOriginalUrl | true if use original url; otherwise, false. |
bool | throwExceptionOnError | Throw exception if error occurs |
ICookieContainer | cookieContainer | The object of cookie container. Use a common collection of cookies between browser and http requests. |
bool | removeDefaultHeaders | true 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);