YTKNetwork
YTKNetwork copied to clipboard
我的app有多个域名,当某个请求失败后,我想切换到另一个域名,然后再次重新请求,怎么实现啊?谢谢
提出问题前请先确认完成了下列几项步骤 New Issue Checklist
- [x] 我已经阅读过 贡献指南 I have read and understood the CONTRIBUTING guide
- [x] 我已经阅读过 程序文档 I have read the Documentation
- [x] 我已经证实这个问题来源于 YTKNetwork 本身,而不是其所依赖的 AFNetworking I have confirmed that this issue is caused by YTKNetwork, not AFNetworking
- [x] 我已经在项目的 问题列表 中搜索过并且没有找到类似问题 I have searched for a similar issue in the project and found none
问题描述 Issue Description
请给出所提出问题的详尽描述,包括具体的错误信息,打印的堆栈等等,以及重现此问题的具体步骤。
Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.
在不改源码的基础上实现,我的思路是: RegisterApi *reg = [[RegisterApi alloc] initWithUsername:@"username" password:@"password"]; [reg startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) { NSLog(@"qingqiu =%@",request.responseString); } failure:^(__kindof YTKBaseRequest * _Nonnull request) { NSLog(@"cuowu =%@",request.error); NewRegisterApi *reg = [[NewRegisterApi alloc] initWithUsername:@"username" password:@"password"]; [reg startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) { NSLog(@"qingqiu =%@",request.responseString); } failure:^(__kindof YTKBaseRequest * _Nonnull request) { NSLog(@"cuowu =%@",request.error); }]; }]; NewRegisterApi和RegisterApi一样的实现,除了要重写baseUrl方法,返回你要请求的新地址。
你可以重写当前请求的 baseUrl
和 buildCustomUrlRequest
方法实现
/// The baseURL of request. This should only contain the host part of URL, e.g., http://www.example.com.
/// See also `requestUrl`
- (NSString *)baseUrl;
/// Use this to build custom request. If this method return non-nil value, `requestUrl`, `requestTimeoutInterval`,
/// `requestArgument`, `allowsCellularAccess`, `requestMethod` and `requestSerializerType` will all be ignored.
- (nullable NSURLRequest *)buildCustomUrlRequest;