Giter VIP home page Giter VIP logo

v-request's Introduction

v-requset

突破小程序网络请求限制黑科技 让你更自由地请求任意网站数据

项目地址:https://github.com/guren-cloud/v-request

简介

大家都知道,小程序的http网络请求是非常严格的:

  1. 域名需要备案
  2. 域名需要上https
  3. 需要开发者在后台设置request白名单

所以,这个项目出现了。
得益于小程序的云开发功能,让我们可以突破这个限制,来达到请求任何可访问的http数据!
(如:ip访问、http 80端口访问、自定义端口访问、未备案域名等场景)

安装

部署云函数

项目分为两部分,一个是我们的小程序云函数代码,在cloud目录中。
我们首先在开发者工具开通小程序云开发平台,然后初始化好环境之后,创建一个云函数,命名为:v-request

然后把index.jspackage.json文件的内容替换为项目cloud目录中对应的文件内容,再右键进行上传部署(云端安装依赖)操作:

部署客户端

另一个文件,就是主目录下的v-request.js文件,这个是运行在我们小程序里的SDK客户端文件。
我们把它放入小程序的目录,如utils/目录中,然后在app.js文件中进行require加载即可:

使用

通过上边的部署,我们已经可以在小程序的任意位置进行使用我们的v-request黑科技了!
使用方法很简单,和wx.request官方API的用法基本保持一致
我们只需要把原来的wx.request改成wx.vrequest即可。

GET请求例子

wx.vrequest({
  url: 'https://mssnn.cn',
  success: ret => {
    console.log(ret.data);
  }
})

返回的数据:

POST请求例子

wx.login({
  success: ret => {
    wx.vrequest({
      url: 'https://wx5bbe79dd056cb238.mssnn.cn/v2/client/init',
      data: 'code=' + ret.code,
      dataType: 'json',
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
          },
      success: res => {
        console.log('[post.res]', res);
      }
    })
  }
})

返回的数据:

其他说明

代码仅供学习,请勿滥用或用于非法用途。
本方法由古人云小程序原创研发
欢迎你关注我们学习更多小程序开发技巧!

v-request's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.