search
HomeWeChat AppletMini Program DevelopmentIntroduction to WeChat mini program network request wx.request

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

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use