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);
    })
  • 相关阅读:
    javascript基础
    html基础
    css基础
    django-session和cookie
    rest架构
    django-models
    django-templates
    Alignment
    ural 1225.Flags
    ural 1009. K-based Numbers
  • 原文地址:https://www.cnblogs.com/CyLee/p/9207334.html
Copyright © 2011-2022 走看看