Skip to content

Developer Function: Server Script: httpClient

Overview

Used when using an HTTP client to connect to an external service in a "Server Script".

Supported Versions

RequestHeaders

Pleasanter 1.3.9.0 or later

HttpClient

Pleasanter 1.2.16.0 or later

HttpClient Patch Method

Pleasanter 1.3.50.0 or later

Properties

No Name Get Set Type Description
1 RequestUri Yes Yes string The URI of the destination
2 Content Yes Yes string Data to send
3 Encoding Yes Yes string Encoding (default is "utf-8")
4 MediaType Yes Yes string Media type (default is "application/json")
5 RequestHeaders Yes No Dictionary Request header. See below for more details.
6 IsSuccess Yes No bool Get whether the most recent request was successful. Returns True if the StatusCode is within the range of 200-299.
7 StatusCode Yes No int Status code of the response message for the most recent request.

Example Usage of RequestHeaders Property

You can add any request header by using the Add method of the RequestHeaders property as shown below.

httpClient.RequestHeaders.Add({Header name}, {Value});

Basic Authentication with Authorization Header

let base64 = utilities.ConvertToBase64String('userName:password');
httpClient.RequestHeaders.Add("Authorization", "Basic " + base64);
httpClient.RequestUri= "https://servername/api/.....";
let result = httpClient.Get();

*To convert a string to Base64, you can use the "utilities.ConvertToBase64String" method.

Also, if you want to set another header and send it subsequently, reset the header content with the Clear method.

httpClient.RequestHeaders.Clear();
httpClient.RequestHeaders.Add("Authorization", "Bearer " + "X2kKRHGI495Y.......");

Method

No Name Description
1 Get Issue the GET method and receive the results.
2 Post Issue the POST method and receive the results.
3 Put Issue the PUT method and receive the results.
4 Delete Issue the DELETE method and receive the results.
5 Patch Issue the PATCH method and receive the results.