nodejs 中 axios 设置 burp 抓取 http 与 https

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

nodejs 中 axios 设置 burp 抓包

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

http

只需要添加 proxy

js 复制代码
// 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

js 复制代码
// 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();
相关推荐
一心赚狗粮的宇叔7 小时前
VScode常用扩展包&Node.js安装及npm包安装
vscode·npm·node.js·web
花间相见7 小时前
【AI开发】—— Ubuntu系统使用nvm管理Node.js多版本,版本切换一键搞定(实操完整版)
linux·ubuntu·node.js
嘿是我呀8 小时前
【用npm安装node时报错“npm 无法加载文件”】
前端·npm·node.js
西门吹-禅1 天前
prisma
node.js
怪兽毕设1 天前
基于SpringBoot的选课调查系统
java·vue.js·spring boot·后端·node.js·选课调查系统
心.c1 天前
Vue3+Node.js实现文件上传分片上传和断点续传【详细教程】
前端·javascript·vue.js·算法·node.js·哈希算法
roamingcode1 天前
我是如何 Vibe Coding,将 AI CLI 工具从 Node.js 迁移到 Rust 并成功发布的
人工智能·rust·node.js·github·claude·github copilot
Stream_Silver3 天前
【Node.js 安装报错解决方案:解决“A later version of Node.js is already installed”问题】
node.js
Anthony_2313 天前
基于 Vue3 + Node.js 的实时可视化监控系统实现
node.js
说给风听.3 天前
解决 Node.js 版本冲突:Windows 系统 nvm 安装与使用全指南
windows·node.js