User Manual

10.04.2024

MANUAL

Developer Function: Server Script: httpClient.Post

## Overview Used when issuing a POST method using ["httpClient"](server-script-http-client) in "[Server Script](/en/manual/table-management-server-script)". ## Syntax ``` httpClient.Post(); ``` ## Parameters There are no parameters. ## Return Value String-type return value ## Usage Example The following example issues a POST method to an external API server and logs the results. ##### JavaScript MediaType: application/json example ``` let data = { data1: 'abc', data2: '123' } httpClient.RequestUri = 'https://servername/api/.....'; httpClient.Content = JSON.stringify(data); let response = httpClient.Post(); if(httpClient.IsSuccess) { context.Log('Success: ' + response); }else{ context.Log('Error: (' + httpClient.StatusCode + ')' + response); } ``` MediaType: application/x-www-form-urlencoded example ``` let data = { data1: 'abc', data2: '123' } httpClient.RequestUri = 'https://servername/api/.....'; httpClient.MediaType = 'application/x-www-form-urlencoded'; httpClient.Content = createParameters(data); let response = httpClient.Post(); if(httpClient.IsSuccess) { context.Log('Success: ' + response); }else{ context.Log('Error: (' + httpClient.StatusCode + ')' + response); } //Function to convert the object to URL-encoded parameter format function createParameters(obj) { let result =[]; for(var key in obj) { result.push(encodeURIComponent(key) + '=' +encodeURIComponent(obj[key])); } return result.join('&'); } ``` ## Related Information <div id="ManualList"><ul><li><a href="/en/manual/table-management-server-script">Table Management: Server Script</a><span>08.13.2024 up</span></li></ul></article></div><input id="SearchTextHidden" type="hidden" value="" />
TOP
このページをシェアする
記載された商品名、各製品名は各社の登録商標または商標です。 © Implem Inc.