• 搭建代理服务器时的笔记,request使用笔记


    request 请求笔记:

    1、opation中使用form字段传参 对应 content-type': 'application/x-www-form-urlencoded',如果想要content-type设置为

    var options = {
      url: "http://localhost:8888/getjs",
      method:'POST',
      form:{
        limit: 20,
        offset: 0,
        orderId:'',
        receiverPhone:'',
        skuId:'',
        skuName:''
      }
    }; 
    request(options, (error, response, body)=>{
      // console.log(" response:===",response);
        console.log(" ============body begin============");
        console.log(body);
        console.log(" ============body end============");
        console.log("[response.headers]:",response.headers)
      if (!error && response.statusCode == 200) {
        // var info = JSON.parse(body);
      }
    });

    注意必须设置的几个字段  json 、headers中的content-type 还有不能使用form字段  必须用body

    var options = {
      url: localurl_localhost,
      method:'POST',
      json:true,//这个字段必须
      headers:{
        'content-type':'application/json', //这个字段必须
      },
      body:{ //想要发起 content-type为application/json的请求  就要用body字段传参
        limit: 20,
        offset: 0,
        orderId:'',
        receiverPhone:'',
        skuId:'',
        skuName:''
      }
    };

     2、注意,Content-Length最好不填,不填的话,require会默认计算长度并填入,反而更安全,因为如果填写有误的话会直接影响返回值,写小了,body参数传递不全,写长了可能会报错

  • 相关阅读:
    C# 文件上传下载
    javaScript的三种储存方式
    XDocument常用属性
    NoSQL
    SQLserver 的分页存储过程
    Redis Wendows安装步骤
    C#和JS获取时间
    api跨域
    以太坊开发DApp入门教程——区块链投票系统(一)
    android和java以太坊开发区块链应用使用web3j类库
  • 原文地址:https://www.cnblogs.com/liujinyu/p/10001940.html
Copyright © 2020-2023  润新知