Home > Article > WeChat Applet > WeChat applet wx.request request data error
First write a background data interface, the address is: http://localhost/weicms/index...
Then use wx.request to call the address of the background data interface
Sample code
1 wx.request({ 2 url: 'http://localhost/weicms/index.php?s =/addon/Cms/Cms/getList', 3 data: { 4 x: '', 5 y: '' 6 }, 7 header: { 8 'content-type': 'application/json'// 默认值 9 }, 10 success (res) { 11 console.log(res.data) 12 } 13 })
Run the code, the effect is as follows:
From the picture above, you can see that the page is blank and no data is obtained. , and the console reports an error (request legal domain name verification error; http://localhost is not in the following request legal domain name list)
Why does this error occur?
Open the development document of wx.request network request and you can see
The red box in the screenshot above is the problem (mini program server domain name configuration IP address and localhost cannot be used). The URL address requested by wx.request in the sample code contains localhost, so an error occurs.
But in general, during the development process, you must first develop and debug locally. If the IP address and localhos cannot be used, how to obtain data during local development and debugging? Is there any way to shield this error during local development and debugging?
The answer is yes. The development documentation points out that domain name verification can be skipped, as shown below:
Where exactly do I turn on the option of not verifying the domain name? In the WeChat developer tools, after clicking Details, select Do not verify legal domain names, as shown in the following figure:
At this time, after running the code again, the effect is as follows:
You can see from the above picture that the data has been successfully obtained, and the control has not reported an error. It just prompts: Close the legal domain name, web-view (business domain name), and TLS version in the configuration. And HTTPS certificate check
Recommended tutorial: "WeChat Mini Program"
The above is the detailed content of WeChat applet wx.request request data error. For more information, please follow other related articles on the PHP Chinese website!