小程序模板网

微信小程序lianc++后台

发布时间:2018-02-01 18:29 所属栏目:小程序开发教程

贴上微信小程序发送http请求代码:

 

[javascript] view plain copy
 
  1. onsend: function(){      
  2.    wx.request({  
  3.       url: 'http://127.0.0.1:1000', //c++后台ip、端口  
  4.       data: {  
  5.           x: '1' , //发送到后台字段  
  6.           y: '2'  
  7.  },  
  8.  header:{  
  9.      "Content-Type":"application/json"  
  10.  },  
  11.  method:"POST", //发送POST,若为GET则改为GET  
[javascript] view plain copy
 
  1. success: function(res) {  
  2.    var data = res.data;  
  3.    console.log(data);  
  4. }  
  5. });  
  6. }  

c++后台代码借鉴boost官网的asio的http server 3地址并自己做了修改:

 

官网地址:http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/examples.html

修改代码:

1、request_parser.hpp:

 

[cpp] view plain copy
 
  1. //  
  2. // request_parser.hpp  
  3. // ~~~~~~~~~~~~~~~~~~  
  4. //  
  5. // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)  
  6. //  
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying  
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  
  9. //  
  10.   
  11. #ifndef HTTP_SERVER3_REQUEST_PARSER_HPP  
  12. #define HTTP_SERVER3_REQUEST_PARSER_HPP  
  13.   
  14. #include <boost/logic/tribool.hpp>  
  15. #include <boost/tuple/tuple.hpp>  
  16.   
  17. namespace http {  
  18. namespace server3 {  
  19.   
  20. struct request;  
  21.   
  22. /// Parser for incoming requests.  
  23. class request_parser  
  24. {  
  25. public:  
  26.   /// Construct ready to parse the request method.  
  27.   request_parser();  
  28.   
  29.   /// Reset to initial parser state.  
  30.   void reset();  
  31.   
  32.   /// Parse some data. The tribool r


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/21402.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询