Home > WeChat Applet > Mini Program Development > Introduction to WeChat mini program network request wx.request

Introduction to WeChat mini program network request wx.request

不言
Release: 2018-06-27 13:57:10
Original
3146 people have browsed it

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.

  1. GET: Make a request to a specific resource.

  2. POST: Submit data to the specified resource for processing request. The data is included in the request body.

  3. PUT: Upload the latest content to the specified resource location.

  4. DELETE: Request the server to delete the resource identified by the Request-URI.

  5. HEAD: Ask the server for a response consistent with the GET request, but the response body will not be returned.

  6. TRACE: Echo the request received by the server, mainly used for testing or diagnosis

  7. OPTIONS: Return the server's support for specific resources HTTP request method.

  8. 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)
    }
  })
Copy after login

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)
    }
  })
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template