How to use Fiddler to intercept https requests from axios

huangapple go评论68阅读模式
英文:

How to use Fiddler to intercept https requests from axios

问题

我正在使用Electron编写一个爬虫,其中使用了Axios库。但是当我发送请求时,我发现在开发者工具的网络选项卡中没有我的请求记录,所以我想使用Fiddler来捕获Axios发送的HTTPS请求以进行调试。

但是当我将请求发送到Fiddler时,我遇到了解析SSL的问题。我确保在Fiddler中打开了"Trust Root Certificate"、"Capture Https traffic"和"Allow remote computers to connect"选项。

以下是我的Axios测试代码:

const axios = require("axios");

// 获取谷歌首页
axios
  .get("https://www.google.com", {
    proxy: {
      host: "127.0.0.1",
      port: 8866,
    },
  })
  .then((res) => {
    console.log(res.data);
  })
  .catch((err) => {
    console.log(err);
  });

在Fiddler中,我得到了以下消息:

发现了一个兼容SSLv3的ClientHello握手。Fiddler提取了以下参数。

或者是否有办法让Axios在Electron的开发者工具中获取网络信息?

以下是我在Python中测试的代码,在Fiddler中可以正常工作:

import requests

proxies = {
    'http': '127.0.0.1:8866',
    'https': '127.0.0.1:8866'
}

requests.get('https://www.google.com', proxies=proxies, verify=False)

希望对你有帮助!

英文:

I'm writing a crawler using electron which uses Axios, but when I send a request I find that Network in devtools doesn't have my request, so I want to use a fiddler to capture the https request from axios to debug it.

But when I sent the request to fiddler I had problems parsing ssl.
I made sure I turned on Trust Root Certificate,Capture Https traffic,Allow remote computers to connect in fiddler.

Here is my Axios test code.

const axios = require("axios");

//get google
axios
  .get("https://www.google.com", {
    proxy: {
      host: "127.0.0.1",
      port: 8866,
    },
  })
  .then((res) => {
    console.log(res.data);
  })
  .catch((err) => {
    console.log(err);
  });

In Fiddler I get the following message.

> A SSLv3-compatible ClientHello handshake was found. Fiddler extracted
> the parameters below.

Or is there any way to make axios get network information in electron's devtools?

Here's the code I tested in python, and it works correctly in Fiddler.

import requests
proxies = {
    'http': '127.0.0.1:8866',
    'https': '127.0.0.1:8866'
}
requests.get('https://www.google.com',proxies=proxies,verify=False)

答案1

得分: 0

原文翻译如下:

原来是因为我在主进程中运行Axios而不是在渲染进程中,所以网络没有发送请求。

在渲染进程中运行请求,然后使用Fiddler捕获到了该请求。

英文:

It turns out that the network isn't requesting it because I'm running Axios in the main process and not in the rendering process.

> Running the request in the rendering process and then using Fiddler
> catches the request.

huangapple
  • 本文由 发表于 2023年8月8日 23:33:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定