dlt.request
Introduction
Network request, currently supports (post, get, put, delete, POST_JSON, POST_MULTIPART)
Parameters
Object object
Attribute | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
url | string | Yes | Request URL | ||
data | string | No | Request parameters, if it is JSONObject data, the value type needs to be a string | Supported after version 3.0.0, for versions below 3.0.0, the parameter name is dataJson and the type is string | |
header | string | No | Set the request header, JSON string structure | ||
timeout | number | 60000 | No | Timeout time in milliseconds. The default value is 60000. | Supported after version 3.0.0 |
dataType | string | No | The format of the returned data, the default is to return string type data. | Supported after version 3.0.0 | |
success | function | No | Callback function for successful API call | ||
fail | function | No | Callback function for failed API call | ||
complete | function | No | Callback function for the end of the API call (both success and failure will be executed) |
dataType Legal Values
Legal Value | Description |
---|---|
json | The returned data is JSON, and after returning, JSON.parse will be performed on the returned data. |
Others | Do not perform JSON.parse on the returned content. |
object.success Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
statusCode | string | Response code returned by the server |
response | string | Content returned by the server |
headers | string | Server returned headers, JSON string structure |
cookies | string | Cookies returned by the server, JSON string array; Example: '[{"name":"", "value":"", "expiresAt":"", "domain":"", "path":"", "secure":"", "httpOnly":"", "persistent":"","hostOnly":""}]' |
success | string | true-Set successfully |
object.fail Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
errCode | string | Error code |
errMsg | string | Error message |
success | string | false-Set failed |
errMsg Explanation
Error Message | Description |
---|---|
Http Request Fail, url is empty:R001 | Request failed: url is empty |
Http Request Fail, Exception_" + t.toString() + ":R002 | Request failed: Exception occurred |
Http Request Fail, request method not in " + Arrays.toString(requestMethods) + ":R003 | Request failed: The request method is not within the supported range |
Http Request Fail, onFailure_${e.toString()}:R004 | Request failed |
Http Request Fail, onResponse_${e.toString()}:R005 | Request 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);
},
});
},
});