ZennoLab Assemblies Documentation
Request(HttpMethod,String,String,String,String,String,ResponceType,Int32,String,String,Boolean,Int32,String[],String,Boolean,Boolean,ICookieContainer) Method
Example 
ZennoLab.CommandCenter Namespace > ZennoPoster.HTTP Class > Request Method : Request(HttpMethod,String,String,String,String,String,ResponceType,Int32,String,String,Boolean,Int32,String[],String,Boolean,Boolean,ICookieContainer) Method

Type: ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod

HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)

Type: System.String

Target address of request.

Type: System.String

Specifies the content of POST, PUT or PATCH request.

For other methods empty string can be used.

Type: System.String

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"

Type: System.String

Proxy string (for example: "socks5://login:pass@8.5.6.7:8080").

Type: System.String

Specifies the encoding to use.

Default value is "UTF-8"

Type: ZennoLab.InterfacesLibrary.Enums.Http.ResponceType

Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).

Type: System.Int32

Request timeout in milliseconds.

Default values is 30000 (30 seconds).

Type: System.String

Cookies for request.

Type: System.String

Specifies value for "User-Agent" header.

Type: System.Boolean

true if redirects should be followed.

Default value is true

Type: System.Int32

Maximum count of redirects.

Default values is 5

Type: System.String[]

Array of additional headers and values that will be added to request.

Default value is null

Type: System.String

Download path for file.

Default value is null

Type: System.Boolean

true if use original url; otherwise, false.

Throw exception if error occurs

Type: ZennoLab.InterfacesLibrary.ProjectModel.Collections.ICookieContainer

The object of cookie container. Use a common collection of cookies between browser and http requests.

Executes http request of given method
Syntax

Parameters

method

Type: ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod

HTTP Method to execute (can take values GET, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, PATCH)

url

Type: System.String

Target address of request.

content

Type: System.String

Specifies the content of POST, PUT or PATCH request.

For other methods empty string can be used.

contentPostingType

Type: System.String

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"

proxy

Type: System.String

Proxy string (for example: "socks5://login:pass@8.5.6.7:8080").

Encoding

Type: System.String

Specifies the encoding to use.

Default value is "UTF-8"

respType

Type: ZennoLab.InterfacesLibrary.Enums.Http.ResponceType

Specifies what parts of response should be returned (can take values: BodyOnly, HeaderOnly, HeaderAndBody,File,FileAndHeaders).

Timeout

Type: System.Int32

Request timeout in milliseconds.

Default values is 30000 (30 seconds).

Cookies

Type: System.String

Cookies for request.

UserAgent

Type: System.String

Specifies value for "User-Agent" header.

UseRedirect

Type: System.Boolean

true if redirects should be followed.

Default value is true

MaxRedirectCount

Type: System.Int32

Maximum count of redirects.

Default values is 5

AdditionalHeaders

Type: System.String[]

Array of additional headers and values that will be added to request.

Default value is null

DownloadPath

Type: System.String

Download path for file.

Default value is null

UseOriginalUrl

Type: System.Boolean

true if use original url; otherwise, false.

throwExceptionOnError

Throw exception if error occurs

cookieContainer

Type: ZennoLab.InterfacesLibrary.ProjectModel.Collections.ICookieContainer

The object of cookie container. Use a common collection of cookies between browser and http requests.

Return Value

Type: System.String

The result of request.

Example
The following example shows call the Http method.
var response = ZennoPoster.HTTP.Request(ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://httpbin.org/get?a=b", respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody);
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);
// 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;
// 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;
$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);
Requirements

Target Platforms: Desktop: Windows XP SP3 and older. Server: Windows Server 2003 and older.

See Also

Reference

ZennoPoster.HTTP Class
ZennoPoster.HTTP Members
Overload List