In the event of any inconsistency between the English version and the translated version, the English versionwill take priority. Please visit this page for more information.
For SSL and agentOptions: SSL オプションを設定するか、 agentOptionsオブジェクトを提供する場合は、HTTP リクエストがインストゥルメントされたグローバル エージェントを使用するように、リクエストoptionsオブジェクトのagentプロパティを$globalAgents.httpsまたは$globalAgents.httpに設定する必要があります。
SSLオプションまたはagentOptionsの使用の例:
この例では、agentOptionsを使用します。
//Declare optional metadata
var options = {
//Specify the endpoint URL
url: 'https://api-endpoint.example.com',
//Specify optional headers
headers: {
'Endpoint-Key': 'uqNTC57Phe72pnnB8JuJmwAr7b09nKSKSz',
'Additional-Header': 'Additional-Header-Data'
}
//Specify global agent as the http agent
agent: $globalAgents.https,
//Set SSL option
strictSSL: true,
//Specify http agent options
agentOptions: {
maxVersion: 'TLSv1.1'
},
};
//Define your authentication credentials.
var myAccountID = '{YOUR_ACCOUNT_ID}';
var myLicenseKey = '{YOUR_LICENSE_KEY}';
//Import the 'assert' module to validate results.
var assert = require('assert');
var options = {
//Define endpoint URL.
url: "https://insights-collector.newrelic.com/v1/accounts/"+myAccountID+"/events",
//Define body of POST request.
body: '[{"eventType":"SyntheticsEvent","integer1":1000,"integer2":2000}]',
//Define New Relic license key and expected data type.
headers: {
'Api-Key': myLicenseKey,
'Content-Type': 'application/json'
}
};
//Define expected results using callback function.
function callback(error, response, body) {
//Log status code to Synthetics console.
console.log(response.statusCode + " status code")
//Verify endpoint returns 200 (OK) response code.
assert.ok(response.statusCode == 200, 'Expected 200 OK response');
//Parse JSON into variable.
var info = JSON.parse(body);
//Verify that `info` contains element named `success` with a value of `true`.
assert.ok(info.success == true, 'Expected True results in Response Body, result was ' + info.success);
//Log end of script.
console.log("End reached");
}
//Make POST request, passing in options and callback.
$http.post(options, callback);