Home  >  Article  >  WeChat Applet  >  Mini Program Development--Network Request wx.request Example Tutorial

Mini Program Development--Network Request wx.request Example Tutorial

零下一度
零下一度Original
2017-05-24 09:24:562769browse

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 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

3. 微信小programdemo:阳Tao

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!

Statement:
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