http.post(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Sends an HTTP POST request.

Important:

If negotiating a connection to the destination server exceeds 5 seconds, a connection timeout occurs. If transferring a payload to the server exceeds 45 seconds, a request timeout occurs.

Returns

http.ClientResponse or http.ServerResponse

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

10 units

Module

N/http Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.body

string | Object

required

The POST data.

Note:

Sending a file using multipart/form-data content type in the options.body parameter is not supported.

2015.2

options.url

string

required

The HTTP URL being requested.

For information about resolving a URL, see N/url Module. For information about getting the URL for a script, including Suitelets, see url.resolveScript(options).

2015.2

options.headers

Object

optional

The HTTP headers.

For more information, see HTTP Header Information.

2015.2

Errors

Error Code

Message

Thrown If

SSS_INVALID_HOST_CERT

An untrusted, unsupported, or invalid certificate was found for this host.

The client and server could not negotiate the desired level of security. The connection is no longer usable.

You may also receive this error if the domain name in the options.url parameter is spelled incorrectly or does not use valid syntax. Verify that the domain name:

  • Has 63 or fewer characters

  • Contains alphanumeric characters (a-z, A-Z, 0-9) or hyphens

  • Starts with a letter

  • Ends with a letter or digit

SSS_INVALID_URL

The URL must be a fully qualified HTTP/HTTPS URL.

The URL specified in the options.url parameter must be a fully qualified URL.

For information about resolving a URL, see N/url Module.

SSS_MISSING_REQD_ARGUMENT

Missing a required argument: {param name}.

The options.body or options.url parameter is not specified.

SSS_REQUEST_LOOP_DETECTED

This script executes a recursive function that has exceeded the limit for the number of times a script can call itself using an HTTP request. Please examine the script for a potential infinite recursion problem.

A script is calling back into itself recursively using an HTTP/HTTPS request.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/http Module Script Samples.

          // Add additional code 
...
var headerObj = {
    name: 'Accept-Language',
    value: 'en-us'
};
var response = http.post({
    url: 'http://www.testwebsite.com',
    body: 'My POST Data',
    headers: headerObj
});

var myresponse_body = response.body; // see http.ClientResponse.body
var myresponse_code = response.code; // see http.ClientResponse.code
var myresponse_headers = response.headers; // see http.Clientresponse.headers
...
// Add additional code 

        

Related Topics

N/http Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices