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 request string
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, PUT;
2 . The requested method type needs to be enclosed in single quotes or double quotes;
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 students who are accustomed to using request.getParameter() to obtain parameters, please note
5. If you use the default header, the server needs to "transfer the string" for the transmitted content.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Usage of wx:for and wx:for-item in WeChat mini program
The above is the detailed content of Introduction to WeChat mini program network request wx.request. For more information, please follow other related articles on the PHP Chinese website!