fetch java_拦截Java语言中的Fetch()API响应和请求

我想拦截Javascript中的提取API请求和响应。

例如:在发送请求之前,要拦截请求URL,一旦获得响应,就要拦截响应。

以下代码用于拦截所有XMLHTTPRequest的响应。

(function(open) {

XMLHttpRequest.prototype.open = function(XMLHttpRequest) {

var self = this;

this.addEventListener("readystatechange", function() {

if (this.responseText.length > 0 && this.readyState == 4 && this.responseURL.indexOf('www.google.com') >= 0) {

Object.defineProperty(self, 'response', {

get: function() { return bValue; },

set: function(newValue) { bValue = newValue; },

enumerable: true,

configurable: true

});

self.response = 'updated value' //Intercepted Value

}

}, false);

open.apply(this, arguments);

};

})(XMLHttpRequest.prototype.open);

我想为Fetch()API实现相同的功能。

提前致谢..

你可能感兴趣的:(fetch,java)