nodejs 中 axios 设置 burp 抓取 http 与 https

在使用 axios 库的时候,希望用 burp 抓包查看发包内容。但关于 axios 设置代理问题,网上提到的一些方法不是好用,摸索了一段时间后总结出设置 burp 代理抓包的方法。

nodejs 中 axios 设置 burp 抓包

根据请求的站点,分为 http 和 https 两个类型。

http

只需要添加 proxy

// http 测试网站: http://www.5icool.org/

import https from "https";
import axios from "axios";

const proxy = {
    protocol: 'http',   // 这里设置协议为 http
    host: '127.0.0.1',
    port: 8080
}


async function test() {
    const res = await axios.post("http://www.5icool.org/", {
        title: 'foo',
        body: 'bar',
        userId: 1,
    }, {
        proxy: proxy   // http 站点,就直接设置  proxy 参数
        headers: {'Content-type': 'application/json; charset=UTF-8'},
    })
    console.log(res.data)

}

await test();



https

要添加 proxy 以及 httpsAgent

// https 测试站点: https://jsonplaceholder.typicode.com/posts

import https from "https";
import axios from "axios";
let httpsAgent = new https.Agent({
    rejectUnauthorized: false,   // 因为是 https over http ,所以需要设置 rejectUnauthorized 为 false
});
const proxy = {
    protocol: 'https',   // 这里要设置 https 
    host: '127.0.0.1',
    port: 8080
}


async function test() {
    const res = await axios.post("https://jsonplaceholder.typicode.com/posts", {
        title: 'foo',
        body: 'bar',
        userId: 1,
    }, {
        httpsAgent: httpsAgent,  // 添加 httpsAgent
        proxy: proxy,   // 添加 proxy
        headers: {'Content-type': 'application/json; charset=UTF-8'},
    })
    console.log(res.data)

}

await test();


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值