new Client()
Example
// create client
var client = new $.net.http.Client();
// where and what to send
var dest = $.net.http.readDestination("testApp", "myDestination");
var request = new $.net.http.Request($.net.http.GET, "/"); // new Request(METHOD, PATH)
// the PATH will be prefixed by destination's pathPrefix, e.g. "/search?" on the request
// send the request and synchronously get the response
client.request(request, dest);
var response = client.getResponse();
// get all the cookies and headers from the response
var co = [], he = [];
for(var c in response.cookies) {
co.push(response.cookies[c]);
}
for(var c in response.headers) {
he.push(response.headers[c]);
}
// get the body
var body;
if(!response.body)
body = "";
else
body = response.body.asString();
// close the connection
client.close(); // prevent socket leak - see xsengine.ini: [communication] - max_open_sockets_per_request
// send the response as JSON
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify({"status": response.status, "cookies": co, "headers": he, "body": body}));
-
close()
-
Close the connection and decrement the sockets_per_request count.
- See:
-
- xsengine.ini: [communication] - max_open_sockets_per_request
-
-
Retrieve the response from the previously sent request synchronously/blocking
Throws:
Throws an error if there is no valid response to return
Returns:
A response object with headers, cookies and the response body
-
Type
-
$.web.WebResponse
-
request(request, destination)
-
Send a new request object to the given destination
Parameters:
Throws:
Throws an error if the request fails or the parameters are invalid
-
request(request, url, proxy)
-
Send a request object to the given URL
Parameters:
Name |
Type |
Argument |
Description |
request |
$.net.http.Request
|
|
The request object to send |
url |
String
|
|
URL to send the request to, e.g. "http://www.google.de/q=HANA" |
proxy |
String
|
<optional>
|
Proxy URL to use for this request, e.g. "http://proxy.mycompany.com:3128" |
Throws:
Throws an error if the request fails or the parameters are invalid
-
request(WebMethod, url, proxy)
-
Send a new request to the given URL, using the specified HTTP method
Parameters:
Name |
Type |
Argument |
Description |
WebMethod |
$.net.http
|
|
The HTTP Method to use for this request ($.net.http.GET/POST/PUT/...) |
url |
String
|
|
URL to send the request to, e.g. "http://www.google.de/q=HANA" |
proxy |
String
|
<optional>
|
Proxy URL to use for this request, e.g. "http://proxy.mycompany.com:3128" |
Throws:
Throws an error if the request fails or the parameters are invalid
-
setTimeout(timeout)
-
Sets the timeout for communication with the server
Parameters:
Name |
Type |
Description |
timeout |
Number
|
Timeout in seconds |
Throws:
Throws an error if the parameter is not a numeric value
-
setTrustStore(trustStore)
-
Sets the default trust store the will be used when issuing https://
requests via request(request, URI, ...)-syntax.
Parameters:
Name |
Type |
Description |
trustStore |
String
|
name |