Home > Article > WeChat Applet > Mini Program Development--Network Request wx.request Example Tutorial
This article mainly introduces the relevant information about the detailed explanation and examples of the WeChat mini program network request wx.request. Friends in need can refer to the following
The detailed explanation and examples of the WeChat mini program network request wx.request
If you say which interface is the most important in the mini program API? Then the first recommendation is wx.request(). This is equivalent to initiating an https request within the mini program (HTTP is supported in local debugging mode). The HTTP protocol defines a total of eight methods or "actions" to indicate different operations on the resources specified by the Request-URI.
GET: Make a request to a specific resource.
POST: Submit data to the specified resource for processing request. The data is included in the request body.
PUT: Upload the latest content to the specified resource location.
DELETE: Request the server to delete the resource identified by the Request-URI.
HEAD: Ask the server for a response consistent with the GET request, but the response body will not be returned.
TRACE: Echo the request received by the server, mainly used for testing or diagnosis
OPTIONS: Return the server's support for specific resources HTTP request method.
CONNECT: The HTTP/1.1 protocol is reserved for proxy servers that can change the connection to a pipeline.
The applet supports all the above 8 methods. However, for network resources, the four types of addition, deletion, modification, and search are enough. The background interface of the mini program mainly uses a method similar to RESTFull.
put requeststring
wx.request({ url: 'https://a86.cn/chishenme/ChishenmeDeciper', method:'PUT', dataType:'STRING', data:'this is strng data 这是一个中文数据', header: {'content-type': 'application/json'}, success:function(res){ console.log('this is put request result'+ res.data) } })
post request string header is different
wx.request({ url: 'https://a86.cn/chishenme/ChishenmeDeciper', method: 'POST', dataType: 'STRING', data:'this is post string data', header: {'content-type':'application/x-www-form-urlencoded'}, success: function (res) { console.log('this is post request result' + res.data) } })
Notes
1. The requested method type must be capitalized, such as GET, POST, and PUT;
2. The requested method type must be in single or double quotes. Included;
3. dataTye needs to be enclosed in single quotes or double quotes (internal conventions also use uppercase letters);
4. Content-type defaults to 'application/json' for customary use Students who obtain parameters with request.getParameter() should pay attention
5. If the default header is used, the server needs to "transfer the string" for the transmitted content
[Related recommendations]
1. WeChat mini program complete source code download
2. Chaige WeChat mini program application store source code
The above is the detailed content of Mini Program Development--Network Request wx.request Example Tutorial. For more information, please follow other related articles on the PHP Chinese website!