Difference between revisions of "HttpRequest class"
Nguyenduyan (talk | contribs) |
|||
Line 1: | Line 1: | ||
{{CGscriptClass_Template | {{CGscriptClass_Template | ||
− | |Name= | + | |Name=HttpRequest |
− | |Description= | + | |Description=Object to make requests to sites |
|Constructors= | |Constructors= | ||
{{CGscriptConstructors_Template|Parameters= | {{CGscriptConstructors_Template|Parameters= | ||
− | {{CGscriptParameters_Template|Type=string|Name= | + | {{CGscriptParameters_Template|Type=string|Name=uri|Description=The uri to visit.}} |
− | |Description= | + | |Description=Visit a uri}} |
{{CGscriptConstructors_Template|Parameters= | {{CGscriptConstructors_Template|Parameters= | ||
− | {{CGscriptParameters_Template|Type=string|Name= | + | {{CGscriptParameters_Template|Type=string|Name=uri|Description=The uri to visit.|Comma=,}}{{CGscriptParameters_Template|Type=WebResponse|Name=takeCookiesFrom|Description=If you made a previous request and want to transfer the cookies from that response, give the response object here.}} |
− | |Description= | + | |Description=Visit a uri with cookies}} |
|Methods= | |Methods= | ||
− | {{CGscriptMethods_Template|ReturnType=WebResponse|Name= | + | {{CGscriptMethods_Template|ReturnType=WebResponse|Name=GetResponse|Description=Actually do the request, and get the response back}} |
− | {{CGscriptMethods_Template|ReturnType=WebResponse|Name= | + | {{CGscriptMethods_Template|ReturnType=WebResponse|Name=GetResponse|Parameters= |
− | {{CGscriptParameters_Template|Type=string|Name= | + | {{CGscriptParameters_Template|Type=string|Name=body|Description=A body to include in the request - Always UTF-8 encoded}} |
− | |Description= | + | |Description=Actually do the request, and get the response back}} |
− | {{CGscriptMethods_Template|ReturnType=string|Name= | + | {{CGscriptMethods_Template|ReturnType=Empty|Name=SetIgnoreCertificatesErrors|Description=Ignore any ssl/tls errors due to certificate validation}} |
+ | {{CGscriptMethods_Template|ReturnType=string|Name=ToString|Description=The string representation of the object.}} | ||
|Properties= | |Properties= | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name= | + | {{CGscriptProperties_Template|ReturnType=string|Name=ContentType|HasGetter=1|HasSetter=1|Description=Get/Set the ContentType}} |
− | {{CGscriptProperties_Template|ReturnType=Dictionary|Name= | + | {{CGscriptProperties_Template|ReturnType=Dictionary|Name=Headers|HasSetter=1|Description=Apply headers to the request}} |
− | {{CGscriptProperties_Template|ReturnType=string|Name= | + | {{CGscriptProperties_Template|ReturnType=string|Name=Method|HasGetter=1|HasSetter=1|Description=Choose which HTTP method to request with}} |
− | {{CGscriptProperties_Template|ReturnType=string|Name= | + | {{CGscriptProperties_Template|ReturnType=string|Name=ObjectTypeName|HasGetter=1|Description=The name of the type of object.}} |
− | {{CGscriptProperties_Template|ReturnType= | + | {{CGscriptProperties_Template|ReturnType=int|Name=Timeout|HasGetter=1|HasSetter=1|Description=Get/Set the timeout (in millisec)}} |
− | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name= | + | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=TypeInformation|HasGetter=1|Description=Get information about this class.}} |
− | }} | + | }} |
− | '''More information about an HTTP Message:''' [http://www.jmarshall.com/easy/http/ http://www.jmarshall.com/easy/http/] | + | <br/>'''More information about an HTTP Message:''' [http://www.jmarshall.com/easy/http/ http://www.jmarshall.com/easy/http/] |
− | ==== <span style="color:#a52a2a | + | ==== <span style="color:#a52a2a">Examples</span> ==== |
− | <span style="color: rgb(165, 42, 42) | + | <span style="color: rgb(165, 42, 42)"><source lang="javascript">string uri = "http://google.com"; |
string responseString; | string responseString; | ||
HttpRequest hr = new HttpRequest(uri); | HttpRequest hr = new HttpRequest(uri); | ||
− | WebResponse wr = hr.GetResponse(); | + | WebResponse wr = hr.GetResponse(); |
responseString = wr.Response(); | responseString = wr.Response(); | ||
print(responseString);</source></span> | print(responseString);</source></span> |
Revision as of 08:15, 24 November 2016
HttpRequest
Object to make requests to sites
Constructors
- (string uri "The uri to visit.") - Visit a uri
- (string uri "The uri to visit.", WebResponse takeCookiesFrom "If you made a previous request and want to transfer the cookies from that response, give the response object here.") - Visit a uri with cookies
Methods
- WebResponse GetResponse() - Actually do the request, and get the response back
- WebResponse GetResponse(string body "A body to include in the request - Always UTF-8 encoded") - Actually do the request, and get the response back
- Empty SetIgnoreCertificatesErrors() - Ignore any ssl/tls errors due to certificate validation
- string ToString() - The string representation of the object.
Properties
- string ContentType { get; set; } - Get/Set the ContentType
- Dictionary Headers { set; } - Apply headers to the request
- string Method { get; set; } - Choose which HTTP method to request with
- string ObjectTypeName { get; } - The name of the type of object.
- int Timeout { get; set; } - Get/Set the timeout (in millisec)
- TypeInformation TypeInformation { get; } - Get information about this class.
More information about an HTTP Message: http://www.jmarshall.com/easy/http/
Examples
string uri = "http://google.com";
string responseString;
HttpRequest hr = new HttpRequest(uri);
WebResponse wr = hr.GetResponse();
responseString = wr.Response();
print(responseString);