


This article talks about the Post request in the development of WeChat applet. If you don’t know about the Post request in the development of WeChat applet or are interested in the Post request in the development of WeChat applet, then Let’s take a look at this article together. Okay, without further ado, let’s get to the point!
1.post request
##wx.request(OBJECT)wx.request
Initiated is an HTTPS request.
A WeChat applet can only have 5 network request connections at the same time.
Official website description
Type | Required | Description | |
---|---|---|---|
String | ## is | Developer server interface address | |
##Object, String | No | Requested parameters | header |
Object | No | Set the request header, Referer cannot be set in the header | method |
String | No | Default is GET, valid values: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT | ##success |
Function | No | Received the successful return from the developer serviceCallback function, res = {data: 'Content returned by the developer server' } | fail |
Function | No | Callback function for interface call failure | complete |
Function | No | The callback function at the end of the interface call (will be executed if the call is successful or failed) | WeChat Mini Program Example ## wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'content-type': 'application/json' }, success: function(res) { console.log(res.data) } })
But POST has a big problem. Code 1): wx.request({ url: ApiHost + '/?service=default.getOrderInfo', data: { 'order_id': order_id }, method: 'POST', success: function (res) { // console.log(res); if (res.data.ret == 200) { //something to do } else{ //something to do } } fail: function (res) { console.log(res); } });Pay attention to the picture below, the prompts in the WeChat development tool: POST request will put the value of data in the Request Payload instead of the Query String Parameters. If the backend server does not pay attention, it will not be able to get the data. wx.request({ url: ApiHost + '/?service=default.getOrderInfo', data: { //数据urlencode方式编码,变量间用&连接,再post 'order_id='+order_id }, method: 'POST', header:{ 'content-type':'application/x-www-form-urlencoded' }, success: function (res) { // console.log(res); if (res.data.ret == 200) { //something to do } else{ //something to do } } fail: function (res) { console.log(res); } });If you modify it like this, the backend does not need special processing. But... I am using the Phalapi framework here, I recommend it~~~ if(DI()->request->getHeader('content-type')) { $contentType = DI()->request->getHeader('content-type'); } if(!empty($contentType)&&(strtolower(@$contentType) === 'application/json')) { $HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : "{}"; DI()->request = new PhalApi_Request(array_merge($_GET,json_decode($HTTP_RAW_POST_DATA, true))); }Finally, I passed the debugging using code one on the PC. Use standard requests and do not use the application/x-www-form-urlencoded mode. But...when I use a real machine for debugging, why can't I receive therequest parameters again? Strange things. . . . . . . . . Finally through packet capture analysis
POST /?service=default.getOrderInfo HTTP/1.0 Host: proxy Connection: close Content-Length: 43 Origin: http://###.appservice.open.weixin.qq.com X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 appservice webview/100000 content-type: application/json Accept: */* Referer: https://servicewechat.com/####/devtools/page-frame.html Accept-Encoding: gzip, deflate, br {"order_id":"011T00wO0gZVR72P89tO0DFNvO0T00w0"} Finally found the difference: Content-Type and content-type
|
The above is the detailed content of Detailed explanation of Post request in WeChat applet development. For more information, please follow other related articles on the PHP Chinese website!

小程序能用react,其使用方法:1、基于“react-reconciler”实现一个渲染器,生成一个DSL;2、创建一个小程序组件,去解析和渲染DSL;3、安装npm,并执行开发者工具中的构建npm;4、在自己的页面中引入包,再利用api即可完成开发。

对于PHP开发者来说,使用POST带参数跳转页面是一项基本技能。POST是HTTP中一种发送数据的方法,它可以通过HTTP请求向服务器提交数据,跳转页面则是在服务器端进行页面的处理和跳转。在实际开发中,我们经常需要使用POST带参数来跳转页面,以达到一定的功能目的。

PHP是一种广泛使用的服务器端脚本语言,它可以用于创建交互式和动态的Web应用程序。在开发PHP应用时,我们通常需要通过表单将用户输入数据提交给服务器端处理。然而,有时候我们需要在PHP中判断是否有表单数据被提交,这篇文章将介绍如何进行这样的判断。

python模拟浏览器发送post请求importrequests格式request.postrequest.post(url,data,json,kwargs)#post请求格式request.get(url,params,kwargs)#对比get请求发送post请求传参分为表单(x-www-form-urlencoded)json(application/json)data参数支持字典格式和字符串格式,字典格式用json.dumps()方法把data转换为合法的json格式字符串次方法需要

一、java调用post接口1、使用URLConnection或者HttpURLConnectionjava自带的,无需下载其他jar包URLConnection方式调用,如果接口响应码被服务端修改则无法接收到返回报文,只能当响应码正确时才能接收到返回publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

实现如下:server{listen80;listen443ssl;server_namenirvana.test-a.gogen;ssl_certificate/etc/nginx/ssl/nirvana.test-a.gogen.crt;ssl_certificate_key/etc/nginx/ssl/nirvana.test-a.gogen.key;proxy_connect_timeout600;proxy_read_timeout600;proxy_send_timeout600;c

标题:PHP代码示例:使用POST方式传参并实现页面跳转的方法在Web开发中,经常会涉及到如何通过POST方式传递参数,并在服务器端进行处理后实现页面跳转的需求。PHP作为一种流行的服务器端脚本语言,提供了丰富的函数和语法来实现这一目的。下面将通过一个实际的示例来介绍如何使用PHP来实现这一功能。首先,我们需要准备两个页面,一个用来接收POST请求并处理参数

PHP是一种广泛应用于网站开发的编程语言,而页面跳转并携带POST数据是在网站开发中常见的需求。本文将介绍如何实现PHP页面跳转并携带POST数据,包括具体的代码示例。在PHP中,页面跳转一般通过header函数实现。如果需要在跳转过程中携带POST数据,可以通过以下步骤完成:首先,创建一个包含表单的页面,用户在该页面填写信息并点击提交按钮。在表单的acti


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
