WeChat applet network request implementation process analysis

This article mainly introduces the resolution of WeChat applet network request implementation, and the presentation of the sample code is very detailed. It has certain reference value for everyone’s learning or work. Friends needed can refer to

Configuring Server Domain Name:

Each WeChat applet requires a communication domain name in advance, and the applet can only communicate with the specified domain name.

Server domain name: Small program background => development => Development setting => Server domain name configuration, configuring:

1. High domain name only support HTTPS (Request, UploadFile, Downloadfile ) And the WSS (ConnectSocket) protocol.

2. The domain name cannot use IP addresses or localhost.

3. The domain name must be filed by ICP.

4. The server domain name can be applied for 5 modifications within one month.

Call the wx.request (object) method initiated the GET request, the code is as follows:

GET: Function () {wx.Request ({// Request Address (must be based on HTTPS protocol) URL: ‘https://wx.164.red/test’, // Send data DATA: {Name : “ZHANGSAN”, AGE: ’20’}, // Successful callback function success after success (result) {console.log (result)}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}})}}
Running a POST request:
   call wx.request(Object) method initiated POST request 

POST: function () {wx.Request ({// Request address (must be based on HTTPS protocol) URL: ‘https: // Www.baidu.com/api/post ‘, // Setting Request Type, if not set, default Get request Method: “post”, // Send to the server Data: {name: “lisi”, age:’ 20 ‘}, success (result) {console.log (“result”}}}}},

small procedure has no cross-domain Restrictions:
  In a normal website, due to the homologous policy limitations of the browser, the cross-domain request issues of data are derived from two mainstream cross-domain issues of JSONP and CORS, but The internal running mechanism of the small program is different from the web, and the code in the applet does not run in the browser, so the cross-domain request restriction problem in which the data is not present.  
The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment