HomeDocs
Skip to main content

dlt.request

Introduction

Network request, currently supports (post, get, put, delete, POST_JSON, POST_MULTIPART)

Parameters

Object object

AttributeTypeDefaultRequiredDescriptionMinimum Version
urlstringYesRequest URL
datastringNoRequest parameters, if it is JSONObject data, the value type needs to be a stringSupported after version 3.0.0, for versions below 3.0.0, the parameter name is dataJson and the type is string
headerstringNoSet the request header, JSON string structure
timeoutnumber60000NoTimeout time in milliseconds. The default value is 60000.Supported after version 3.0.0
dataTypestringNoThe format of the returned data, the default is to return string type data.Supported after version 3.0.0
successfunctionNoCallback function for successful API call
failfunctionNoCallback function for failed API call
completefunctionNoCallback function for the end of the API call (both success and failure will be executed)

dataType Legal Values

Legal ValueDescription
jsonThe returned data is JSON, and after returning, JSON.parse will be performed on the returned data.
OthersDo not perform JSON.parse on the returned content.

object.success Callback Function

Parameters

Object res

AttributeTypeDescription
statusCodestringResponse code returned by the server
responsestringContent returned by the server
headersstringServer returned headers, JSON string structure
cookiesstringCookies returned by the server, JSON string array; Example: '[{"name":"", "value":"", "expiresAt":"", "domain":"", "path":"", "secure":"", "httpOnly":"", "persistent":"","hostOnly":""}]'
successstringtrue-Set successfully

object.fail Callback Function

Parameters

Object res

AttributeTypeDescription
errCodestringError code
errMsgstringError message
successstringfalse-Set failed

errMsg Explanation

Error MessageDescription
Http Request Fail, url is empty:R001Request failed: url is empty
Http Request Fail, Exception_" + t.toString() + ":R002Request failed: Exception occurred
Http Request Fail, request method not in " + Arrays.toString(requestMethods) + ":R003Request failed: The request method is not within the supported range
Http Request Fail, onFailure_${e.toString()}:R004Request failed
Http Request Fail, onResponse_${e.toString()}:R005Request failed

Sample Code

// pages/index/index.js

Page({
request() {
dlt.request({
url: "xxx",
data: JSON.stringify({ x: "xx" }),
method: "POST",
header: JSON.stringify({
"content-type": "application/json",
"Accept-Timezone": "UTC",
"access-token": "xxxxx",
}),
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.