zoukankan      html  css  js  c++  java
  • nodejs 发起http请求

    http://nodejs.cn/api/http.html#http_http_request_options_callback

    http://yijiebuyi.com/blog/8221eb14c8482e7efd1868946e99ea7c.html

    1、源生 http.request 模块的做法

    http.request({
        method: 'POST',
        url: 'http://192.168.0.102',
        headers: {
            // 'Content-Type': 'application/json',
            // 'X-Requested-With': 'XMLHttpRequest',
        },
        // 请求和回发的数据自动转变成了 json 对象
        // 不需要在header中设置'Content-Type': 'application/json',也不需要手动JSON.stringify()转义Body postdata
        json: true,
        body: {
            'Phone': mobile,
            'Code': code,
            'Pwd': pwd,
            'Share': share
        },
    }, function (err, response, body) {
        console.log(body);
    })

    2、request模块(推荐)

    request({
        method: 'POST',
        url: 'http://192.168.0.102',
        headers: {
            // 'Content-Type': 'application/json',
            // 'X-Requested-With': 'XMLHttpRequest',
        },
        // 请求和回发的数据自动转变成了 json 对象
        // 不需要在header中设置'Content-Type': 'application/json',也不需要手动JSON.stringify()转义Body postdata
        json: true,
        body: {
            'Phone': mobile,
            'Code': code,
            'Pwd': pwd,
            'Share': share
        },
    }, function (err, response, body) {
        console.log(body);
    })
  • 相关阅读:
    解决maven无法下载jar的问题
    Vue-Router 基础
    VUE自定义组件
    VUE过滤器
    VUE生命周期函数
    VUE表单输入绑定
    VUE计算属性和监听器
    VUE 模板语法
    VUE介绍
    taro3.x: 函数组件createIntersectionObserver
  • 原文地址:https://www.cnblogs.com/CyLee/p/9207334.html
Copyright © 2011-2022 走看看