search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Development Guide: About Network Requests

1. When there is an APPID, network communication can only communicate with the specified domain name. If there is no configuration, the following error will be reported during compilation:

Configuration method:

WeChat Mini Program Development Guide: About Network Requests

Set the domain name
Needs to be in the mini program of the WeChat public platform Set the domain name. You can see the setting options in the setting interface of the WeChat applet:

WeChat Mini Program Development Guide: About Network Requests

Select development settings:

WeChat Mini Program Development Guide: About Network Requests

You can see the server settings:

WeChat Mini Program Development Guide: About Network Requests

#Here we can set the domain names that our APPID can access, and we can set up to two of each type. (Note that only https domain names can be used here. This application process takes a certain amount of time)

2. When there is no APPID, it is much more convenient. You can make network requests at will without limiting the domain name. , however, publishing or previewing on mobile phones is not possible in this case. If you want to officially develop small programs, you still need an https domain name, but for learning, http is enough.

Network requests in mini programs are roughly divided into four types.

· Ordinary HTTPS request (wx.request)
· Upload file (wx.uploadFile)
· Download file (wx.downloadFile)
· WebSocket communication (wx.connectSocket)

Here we mainly talk about wx.request:

Using wx.request, you can initiate an http request. A WeChat applet is limited to only 5 network requests at the same time. Note that it is at the same time.

wx.request({
            url: 'http://192.168.1.137:80/app/guanggao',
            method: 'POST',
            data: {
                 type: "1"
            },
            header: {
                'Accept': 'application/json'
            },
            success: function (res) {
                that.setData({
                    images: res.data.data.guanggao
                })
            }
           fail:function(err){
                console.log(err)
           }
        })

The above code will send an http get request, and the parameters are relatively easy to understand.

· url The url address of the server
· The data request parameter can be in the form of String data: "xxx=xxx&xxx=xxx" or Object data: {"userId":1}
· header Set the header of the request
· method http method, the default is GET request
· success callback for successful interface
· fail callback for failed interface

There is also another parameter that is not included In the code:
· complete is the callback after calling the interface. Regardless of success or failure, the interface will be called.

Timeout setting

has been mentioned in the previous article in app.js Setting networkTimeout can set the timeout for four types of network access:

"networkTimeout":{
   "request": 10000,
   "connectSocket": 10000,
   "uploadFile": 10000,
   "downloadFile": 10000
}

For more WeChat applet development guides: For articles related to network requests, please pay attention to 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),