# RequestTask wx.request(Object object)
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6
initiate HTTPS Network request. Please read carefully before usingRelated notes。
# parameter
# Object object
attribute | type | Default values | Required | Introductions | Minimum version |
---|---|---|---|---|---|
url | string | yes | Developer Server Interface Address | ||
data | string/object/ArrayBuffer | no | Requested parameters | ||
header | Object | no | Set the request header,header Can not be set Referer。content-type Default is application/json | ||
timeout | number | no | Timeout in milliseconds | 2.10.0 | |
method | string | GET | no | HTTP Request method | |
dataType | string | json | no | Data format returned | |
responseType | string | text | no | Data type of response | 1.7.0 |
enableHttp2 | boolean | false | no | open http2 | 2.10.4 |
enableQuic | boolean | false | no | open quic | 2.10.4 |
enableCache | boolean | false | no | open cache | 2.10.4 |
enableHttpDNS | boolean | false | no | Whether or not to open HttpDNS Service. If open, need to be filled in at the same time HttpDNSServiceId 。 HttpDNS See Usage Details Mobile resolution of Http DNS | 2.19.1 |
HttpDNSServiceId | boolean | no | HttpDNS Service provider Id 。 HttpDNS See Usage Details Mobile resolution of Http DNS | 2.19.1 | |
success | function | no | Interface calls the successful callback function | ||
fail | function | no | Interface calls failed callback functions | ||
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
object.method Legal value
value | Introductions | Minimum version |
---|---|---|
OPTIONS | HTTP request OPTIONS | |
GET | HTTP request GET | |
HEAD | HTTP request HEAD | |
POST | HTTP request POST | |
PUT | HTTP request PUT | |
DELETE | HTTP request DELETE | |
TRACE | HTTP request TRACE | |
CONNECT | HTTP request CONNECT |
object.dataType Legal value
value | Introductions | Minimum version |
---|---|---|
json | The data returned is JSON, which is returned once for the returned data JSON.parse | |
Other | Does not perform on the returned content JSON.parse |
object.responseType Legal value
value | Introductions | Minimum version |
---|---|---|
text | The data for the response is text | |
arraybuffer | The data for the response is ArrayBuffer |
# object.success callback
# parameter
# Object res
attribute | type | Introductions | Minimum version |
---|---|---|---|
data | string/Object/Arraybuffer | Data returned by the developer server | |
statusCode | number | Returned by the developer server HTTP Status code | |
header | Object | Returned by the developer server HTTP Response Header | 1.2.0 |
cookies | Array.<string> | Returned by the developer server Cookies, formatted as an array of strings | 2.10.0 |
profile | Object | Some debugging information during the network request,View details | 2.10.4 |
res.profile Structure
attribute | type | Introductions |
---|---|---|
redirectStart | number | The first. HTTP The time when the redirection occurred. There is a jump and redirection within the same domain, otherwise the value is 0 |
redirectEnd | number | Last one. HTTP Time at which the redirection completes. Redirects within the same domain with a jump, otherwise the value is 0 |
fetchStart | number | Components ready to use HTTP Request time to fetch resource, before checking local cache |
domainLookupStart | number | DNS When the domain name query started, if local caching was used DNS Query) or persistent connection, with the fetchStart Value equality |
domainLookupEnd | number | DNS When the domain name query was completed, if local caching was used DNS Query) or persistent connection, with the fetchStart Value equality |
connectStart | number | HTTP(TCP) When a connection is established, and if the connection is persistent, the fetchStart Values are equal. Note that if an error occurs at the transport layer and a connection is reestablished, this shows the time when the newly established connection started |
connectEnd | number | HTTP(TCP) Time to complete the connection establishment (complete handshake), or if the connection is persistent, with the fetchStart Values are equal. Note that if an error occurs at the transport layer and the connection is reestablished, the time when the newly established connection was completed is shown here. Note the end of the handshake, including the establishment of the security connection, SOCKS Authorized by |
SSLconnectionStart | number | Time when the SSL connection was established, or if it is not a secure connection, the value is 0 |
SSLconnectionEnd | number | Time when SSL is established, or if it is not a secure connection, the value is 0 |
requestStart | number | The time when the HTTP request started reading the real document (complete connection establishment), including reading the cache locally. When the connection is reconnected, the time of the new connection is also shown here |
requestEnd | number | When the HTTP request reads the real document ends |
responseStart | number | HTTP Time to start receiving the response (first byte), including reading the cache locally |
responseEnd | number | HTTP Time when the response is complete (to the last byte), including reading the cache locally |
rtt | number | When a request is connected in real time rtt |
estimate_nettype | number | Network State Assessment unknown, offline, slow 2g, 2g, 3g, 4g, last/0, 1, 2, 3, 4, 5, 6 |
httpRttEstimate | number | The protocol layer evaluates the current network's Rtt (for reference only) |
transportRttEstimate | number | Of the current network evaluated by the transport layer based on multiple requests Rtt (for reference only) |
downstreamThroughputKbpsEstimate | number | Evaluate kbps for current network downloads |
throughputKbps | number | Actual downloads from the current network kbps |
peerIP | string | IP currently requested |
port | number | Port currently requested |
socketReused | boolean | Reusing connections |
sendBytesCount | number | Number of bytes sent |
receivedBytedCount | number | Number of bytes received |
protocol | string | Using protocol type, valid value: http 1.1, h2, quic, unknown |
# Return value
# RequestTask
Start from base library version 1.4.0. Please remaining backward compatible.
Request Task Object
# data Parameter specification
The final data sent to the server is String Type, if the data No String Type, is converted to String . The conversion rules are as follows:
- for
GET
Method, converts the data to query string(EncodeURIComponent(k)= encodeURIComponent( in)& encodeURIComponent(k)= encodeURIComponent( in)...
) - for
POST
Method andheader['content-type']
forapplication/json
Data for the data JSON Serialization - for
POST
Method andheader['content-type']
forapplication/x-www-form-urlencoded
Converts the data to query string(encodeURIComponent)(k)= encodeURIComponent( in)& encodeURIComponent(k)= encodeURIComponent( in)...)
# sample code
wx.request({
url: 'example.php', //Just an example, not a real interface address
data: {
x: '',
and: ''
},
header: {
'content-type': 'application/json' // Default values
},
success (res) {
console.log(res.data)
}
})