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

你好,支持挂代理吗? #22

Open
PPLLock opened this issue Sep 15, 2022 · 16 comments
Open

你好,支持挂代理吗? #22

PPLLock opened this issue Sep 15, 2022 · 16 comments

Comments

@PPLLock
Copy link

PPLLock commented Sep 15, 2022

No description provided.

@Suzhibin
Copy link
Owner

使用ip 代理服务器访问网络? @PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 16, 2022 via email

@Suzhibin
Copy link
Owner

我查了下 基本上都使用 NSURLSessionConfiguration 的 requestCachePolicy 进行配置,这个与我的请求库配置冲突。我这有另外一个解决方案,你可以试试看能否解决你的需求,我更新了代码,你重新下载,然后在demo实验下
app启动时 会调用 插件方法setRequestProcessHandler,你可以在RequestTool类中进行配置,所有的网络请求 都会经过这个插件
//预处理 请求插件
[ZBRequestManager setRequestProcessHandler:^(ZBURLRequest * _Nullable request, id _Nullable __autoreleasing * _Nullable setObject) {
request.server=@"http://192.168.1:1";//使用ip 代替请求地址
}];
在请求配置时使用 server和path组合
[ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
request.server=url_server;
request.path=url_path;
}
@PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 16, 2022 via email

@Suzhibin
Copy link
Owner

不客气,反馈对我也是提高。我又更新了代码,你更新下,支持请求失败重新配置 请求对象了
你需要在两个方法设置
1 公共配置 setupBaseConfig 内设置重连次数
2 失败插件 setErrorProcessHandler 内重设 request.server
[ZBRequestManager setupBaseConfig:^(ZBConfig * _Nullable config) {
config.retryCount=1;
}];
[ZBRequestManager setErrorProcessHandler:^(ZBURLRequest * _Nullable request, NSError * _Nullable error) {
request.server=@"192.168.1.1";
}];
@PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 16, 2022 via email

@PPLLock
Copy link
Author

PPLLock commented Sep 16, 2022 via email

@PPLLock
Copy link
Author

PPLLock commented Sep 16, 2022 via email

@Suzhibin
Copy link
Owner

端口拼在ip后面 比如 http://192.168.1.1:5000
开关需要 你自己维护,比如你工程有单例吧,设置一个BOOL值,在setErrorProcessHandler方法内 用该值判断是否需要使用ip,开关方法改动BOOL值即可
@PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 17, 2022 via email

@Suzhibin
Copy link
Owner

在请求时使用 server和path组合 不要使用request.url
[ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
request.server=@"https://www.kankezw.com";
request.path=@"/du/2/2021/8445312.html";
}
[ZBRequestManager setErrorProcessHandler:^(ZBURLRequest * _Nullable request, NSError * _Nullable error) {
request.server=@"192.168.1.1:8080";
}];
@PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 17, 2022 via email

@Suzhibin
Copy link
Owner

要想ip替换 服务器,肯定要有所调整。其实还好,只是把服务器 和路径分开 赋值,这种操作还是很常见的。 @PPLLock

@PPLLock
Copy link
Author

PPLLock commented Sep 18, 2022 via email

@PPLLock
Copy link
Author

PPLLock commented Oct 11, 2022 via email

@PPLLock
Copy link
Author

PPLLock commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants