Connection
Main class that is used to establish a connection and send requests to target sites.
// Gets the content of a PasteBin paste, assuming that we have received its key (`pasteBinKey`) in a prior request.
var connection = new http.Connection('http://pastebin.com/raw/');
connection.addHeader({name: ‘Content-Type’, value: ‘text/plain’});
var response = connection.getSync(pasteBinKey, '');
if (response && response.code === 200) {
var text = '';
response.headers.forEach(function(header) {
text += header.name + ': ' + header.value + '\n';
});
text += '\n' + response.response;
issue.addComment(text);
}
Properties
Name | Type | Description | Read-only |
---|---|---|---|
headers | | A list of headers. | |
url | | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |
Constructors
Connection
Connection(url, sslKeyName, timeout)
Creates an object that lets you establish a connection with a target site.
Parameters
Name | Type | Description |
---|---|---|
url | | The URL of the target site for the connection. Can be empty, as you can specify the URI as a parameter for any request method. |
sslKeyName | | Optional name of the SSL key that is used to establish a secure connection. |
timeout | | Optional parameter that specifies the read timeout for outgoing HTTP requests. |
See Also
doSync
Methods
addHeader
addHeader(header, value)
Adds a new header to the current connection.
Parameters
Name | Type | Description |
---|---|---|
header | | A header object with the structure {name: string, value: string}. If the value parameter is specified separately, the provided string is used as the name of the header. |
value | | The value that is assigned to the header. Only considered when the first parameter is specified as a string. |
Return Value
Type | Description | |
---|---|---|
| The current connection object. |
basicAuth
basicAuth(login, password)
Adds an authorization header with the value returned by the Base64.encode(login + ':' + password) function.
Parameters
Name | Type | Description |
---|---|---|
login | | The login to use for the authorization request. |
password | | The password to use for the authorization request.. |
Return Value
Type | Description | |
---|---|---|
| The current connection object. |
connectSync
connectSync(uri, queryParams)
Executes a synchronous CONNECT request.
Parameters
Name | Type | Description |
---|---|---|
uri | | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
deleteSync
deleteSync(uri, queryParams)
Executes a synchronous DELETE request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
doSync
doSync(requestType, uri, queryParams, payload)
Sends a synchronous HTTP request. Note that instead of passing a proper request type with this method, there are dedicated methods that correspond to each request type that you can call directly. For example, getSync or postSync.
Parameters
Name | Type | Description |
---|---|---|
requestType | | A valid HTTP request type. For a list of supported request types, see REQUEST_TYPES. |
uri | | A relative URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. |
payload | | The payload to be sent in the request. |
Return Value
Type | Description | |
---|---|---|
| An object that represents the HTTP response. |
getSync
getSync(uri, queryParams)
Executes a synchronous GET request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
headSync
headSync(uri, queryParams)
Executes a synchronous HEAD request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
optionsSync
optionsSync(uri, queryParams)
Executes a synchronous OPTIONS request.
Parameters
Name | Type | Description |
---|---|---|
uri | | request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
patchSync
patchSync(uri, queryParams, payload)
Executes a synchronous PATCH request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. |
payload | | The payload to be sent in the request. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
postSync
postSync(uri, queryParams, payload)
Executes a synchronous POST request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
payload | | The payload to be sent in the request. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |
putSync
putSync(uri, queryParams, payload)
Executes a synchronous PUT request.
Parameters
Name | Type | Description |
---|---|---|
uri | | The request URI. The complete URL is a concatenation of the string that is passed to the URL parameter in the Connection constructor and this string. If the URL parameter in the Connection constructor is empty, specify the absolute URL of the target site. |
queryParams | | The query parameters. If an object is passed, its keys are considered to be parameter names. If the payload parameter is empty, the query parameters are passed as a form entity. |
payload | | The payload to be sent in the request. |
Return Value
Type | Description | |
---|---|---|
| An object that represents an HTTP response. |