zoukankan      html  css  js  c++  java
  • 「小程序JAVA实战」小程序和后台api通信(28)

    转自:https://idig8.com/2018/08/19/xiaochengxujavashizhanxiaochengxuhehoutaiapitongxin28/

    开发最重要的就是实操!

    小程序和后台api通信

    • 小程序不能直接访问后台接口必须通过请求的方式
    • 通过内网穿透实现暴露到公网
    • ngrok ngrok.com

    如何使用内网穿透

    • 登录ngrok网站
      >https://ngrok.com

    • 介绍
      >用户直接穿透防火墙,到云端做到互相的访问。

    • 如何使用
      >注册

    下载ngrok

    当前文件夹cmd执行命令

    启动命令,显示online,说明内网穿透成功。

    #ngrok http 指定端口
    ngrok http 8080
    

    request

    https://developers.weixin.qq.com/miniprogram/dev/api/network-request.html

    wx.request({
      url: 'test.php', //仅为示例,并非真实的接口地址
      data: {
         x: '' ,
         y: ''
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function(res) {
        console.log(res.data)
      }
    })
    

    标准的ajax请求,跟咱们之前的jquery基本是一样的,我就不详细说了,就是获取参数的传递。但是小程序内部也封装了很多东西,后面一起实战的时候一起来说。

    PS:下一章节开始实战学习,从数据库的表开始设计。

  • 相关阅读:
    leetcode 买卖股票的最佳时机3
    leetcode 买卖股票的最佳时机Ⅱ
    leetcode 最长有效括号
    C++中的%lld和%I64d区别
    Ural 1095 Nikifor 3 思维+同余性质的利用
    博弈基础
    ural 1091. Tmutarakan Exams
    容斥原理
    一些易错的地方
    codeforces911D Inversion Counting 求逆序数+小trick
  • 原文地址:https://www.cnblogs.com/sharpest/p/10286992.html
Copyright © 2011-2022 走看看