Updated on 2025-03-24 GMT+08:00

Preset HttpUtils Tool APIs

Table 1 Preset HttpUtils tool APIs

API

Description

getCookie

Obtains the value of a cookie.

setCookie

Sets a cookie value.

getI18n

Returns a Vue18n instance.

getCsrfToken

Used when an API of the platform is invoked in AJAX mode.

refreshToken

Access token used to manually refresh the page.

getUrlParam

Obtains parameters in the query string.

getLocalStorage

Obtains the value of a localStorage.

setLocalStorage

Sets the value of a localStorage.

getCookie

Used to obtain the value of a cookie. The usage is as follows:

/* @param {*} cookieID
 */
HttpUtils.getCookie("key")

setCookie

Used to set the cookie value. The usage is as follows:

/* @param {*} key
 * @param {*} value
 */
HttpUtils.setCookie("key","value")

getI18n

It is used to return a Vue18n instance in the initialization phase and is used together with Vue and VueI18n. The usage is as follows:

/* 
 * The Vue18n instance can be assigned an i18n parameter when a new Vue instance is created.
 */
HttpUtils.getI18n({
  locale: HttpUtils.getLocale(), 
  messages: thisObj.getMessages()
})

getCsrfToken

Used to call the platform API in Ajax mode. The usage method is as follows:

/*
 * If the platform bridge is used, the platform automatically adds the csrf-token header to the request header.
 */
HttpUtils.getCsrfToken(function(csrfToken) {
  $.ajax({
    headers: {
      CSRF-Token: csrfToken
    },
  })
});

refreshToken

Used to manually refreshes the access token of the page. Generally, this method is executed to refresh the access token of the page when the exit logic is executed. The usage is as follows:

/* @param {*} connector
  * @param {*} successCallBack
  * @param {*} errorCallback
  */
HttpUtils.refreshToken(connector,successCallBack,successCallBack) 

getUrlParam

Used to obtain parameters in the query string. The usage is as follows:

/* 
 * For example, if the URL of a page is https://10.10.10.1:12900/magno/render/cool__app_0000000000NABzEjpNIH/page1?param=1, run the following command:
 * HttpUtils.getUrlParam("param") returns the value 1 of this parameter.
 */
HttpUtils.getUrlParam("param")

getLocalStorage

Used to obtain the value of a localStorage. The usage is as follows:

/* 
 * @param {*} key
 */
HttpUtils.getLocalStorage("key")

setLocalStorage

Used to set the value of a localStorage. The usage is as follows:

/* @param {string} key
 * @param {string/obj} value
 * @param {number} expires
 */
HttpUtils.setLocalStorage("key","value",1000)

The built-in API allows you to set the expiration time of localstorage. The unit is second.