贴上微信小程序发送http请求代码:
[javascript] view plain copy
- onsend: function(){
- wx.request({
- url: 'https://127.0.0.1:1000', //c++后台ip、端口
- data: {
- x: '1' , //发送到后台字段
- y: '2'
- },
- header:{
- "Content-Type":"application/json"
- },
- method:"POST", //发送POST,若为GET则改为GET
[javascript] view plain copy
- success: function(res) {
- var data = res.data;
- console.log(data);
- }
- });
- }
c++后台代码借鉴boost官网的asio的http server 3地址并自己做了修改:
官网地址:https://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/examples.html
修改代码:
1、request_parser.hpp:
[cpp] view plain copy
- //
- // request_parser.hpp
- // ~~~~~~~~~~~~~~~~~~
- //
- // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
- //
- #ifndef HTTP_SERVER3_REQUEST_PARSER_HPP
- #define HTTP_SERVER3_REQUEST_PARSER_HPP
- #include <boost/logic/tribool.hpp>
- #include <boost/tuple/tuple.hpp>
- namespace http {
- namespace server3 {
- struct request;
- /// Parser for incoming requests.
- class request_parser
- {
- public:
- /// Construct ready to parse the request method.
- request_parser();
- /// Reset to initial parser state.
- void reset();
- /// Parse some data. The tribool r