如何在javascript中截获POST请求并从该请求获取数据?

如何在javascript中截获POST请求并从该请求获取数据?,javascript,ajax,request,xmlhttprequest,http-post,Javascript,Ajax,Request,Xmlhttprequest,Http Post,我需要截获facebook发送的post请求,并从该请求中获取所有数据 我尝试覆盖: let oldXHROpen = window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open = function(method, url, async, user, password) { this.addEventListener('load', function() { // do something wit

我需要截获facebook发送的post请求,并从该请求中获取所有数据

我尝试覆盖:

let oldXHROpen = window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
 
 this.addEventListener('load', function() {
  // do something with the response text
  console.log('req: ', this);
 });
               
 return oldXHROpen.apply(this, arguments);
}
这是可行的,但“this”不包括来自请求本身的数据

当我打开开发人员控制台并查看POST请求时,我可以得到:

await fetch("https://www.facebook.com/ajax/notifications/mark_read.php", {
    "credentials": "include",
    "headers": {
        "Accept": "*/*",
        "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "referrer": "https://www.facebook.com/notifications",
    "body": "__user=42&__a=1&__dyn=longchaintext...",
    "method": "POST",
    "mode": "cors"
});
我需要从请求中获取数据:

{
        "credentials": "include",
        "headers": {
            "Accept": "*/*",
            "Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
            "Content-Type": "application/x-www-form-urlencoded"
        },
        "referrer": "https://www.facebook.com/notifications",
        "body": "__user=42&__a=1&__dyn=longchaintext...",
        "method": "POST",
        "mode": "cors"
    }

我们如何获得这些数据?

你的问题不清楚。