Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代理后,比axios原来的返回多了个xhr对象,导致对返回的response做JSON.stringnify处理报错 #95

Open
hzr5700 opened this issue Aug 24, 2022 · 3 comments · May be fixed by #119

Comments

@hzr5700
Copy link

hzr5700 commented Aug 24, 2022

No description provided.

@hzr5700
Copy link
Author

hzr5700 commented Sep 24, 2022

open: function open(args, xhr) {
var _this = this;
var config = xhr.config = {headers: {}};
config.method = args[0];
config.url = args[1];
config.async = args[2];
config.user = args[3];
config.password = args[4];
config.xhr = xhr;//这边在返回对象中引入了xhr,导致问题
var evName = 'on' + eventReadyStateChange;
if (!xhr[evName]) {
xhr[evName] = function () {
return stateChangeCallback(xhr, _this);
};
}

  // 如果有请求拦截器,则在调用onRequest后再打开链接。因为onRequest最佳调用时机是在send前,
  // 所以我们在send拦截函数中再手动调用open,因此返回true阻止xhr.open调用。
  //
  // 如果没有请求拦截器,则不用阻断xhr.open调用
  if (onRequest) return true;
},

@onezhaoyn
Copy link

open: function open(args, xhr) { var _this = this; var config = xhr.config = {headers: {}}; config.method = args[0]; config.url = args[1]; config.async = args[2]; config.user = args[3]; config.password = args[4]; config.xhr = xhr;//这边在返回对象中引入了xhr,导致问题 var evName = 'on' + eventReadyStateChange; if (!xhr[evName]) { xhr[evName] = function () { return stateChangeCallback(xhr, _this); }; }

  // 如果有请求拦截器,则在调用onRequest后再打开链接。因为onRequest最佳调用时机是在send前,
  // 所以我们在send拦截函数中再手动调用open,因此返回true阻止xhr.open调用。
  //
  // 如果没有请求拦截器,则不用阻断xhr.open调用
  if (onRequest) return true;
},

@hzr5700
能补充一下实际使用中的代码 case 吗?详细说明一下问题,以便跟进处理

@hzr5700
Copy link
Author

hzr5700 commented Nov 8, 2022

使用proxy代理后,然后再执行接口请求axios.get(url).then(response => {return JSON.parse(JSON.stringnify(response))});使用JSON.stringnify处理报错。代理代码:proxy({
//请求发起前进入
onRequest: (config, handler) => {
this.domainFilter(config);
handler.next(config);
}
});

@cyfung1031 cyfung1031 linked a pull request Aug 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants