gpt4 book ai didi

ios - AFNetworking 无法在 GET 请求上创建请求

转载 作者:行者123 更新时间:2023-11-29 12:55:54 24 4
gpt4 key购买 nike

我正在尝试向 Restful 服务发出获取请求。当我在没有请求管理器的情况下使用请求时,此请求在过去 3 周内有效。因为我想发送参数字典而添加了请求管理器后,代码不断崩溃并出现错误:

'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: urlRequest'

我的代码如下。如果我取消注释并用它替换新代码,注释掉的代码仍然有效。为什么我可以从该 URL 发出请求,但不能使用 AFNetworking?

NSString *URLForSend = [NSString stringWithFormat:@"%@%@/", ([_remoteDownloadURLString stringByAppendingString:_getFilesJsonURLString]),_userName ];
NSURL *URL = [NSURL URLWithString:URLForSend];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
self.downloadJsonRequest = [[AFHTTPRequestOperation alloc] initWithRequest:request];//this works to create a a afhttprequestoperation, with the same url
_downloadJsonRequest.responseSerializer =
[AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers];
__unsafe_unretained typeof(self) weakSelf = self;

NSMutableDictionary *mutDictForSend = [[NSMutableDictionary alloc] initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"tokenInfo"]];
[mutDictForSend removeObjectForKey:@"success"];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
[manager GET:URLForSend parameters:mutDictForSend success:^(AFHTTPRequestOperation *operation, id responseObject)
{

NSLog(@"%@", responseObject);
weakSelf.jsonArrayForCaching = responseObject;
[[NSNotificationCenter defaultCenter] postNotificationName:kBIDContentEndingSync object:weakSelf];
[weakSelf gotNewJson:responseObject];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Request Failure Because %@",[error userInfo]);
}];
/*
[_downloadJsonRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{

NSLog(@"%@", responseObject);
weakSelf.jsonArrayForCaching = responseObject;
[[NSNotificationCenter defaultCenter] postNotificationName:kBIDContentEndingSync object:weakSelf];
[weakSelf gotNewJson:responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Request Failure Because %@",[error userInfo]);
}];
[[NSNotificationCenter defaultCenter] postNotificationName:kBIDContentStartingSync object:self];
[_downloadJsonRequest start];
*/

最佳答案

我建议更换行:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

后者调用initWithBaseURL,对AFHTTPRequestOperationManager做一些配置,只是调用[[AFHTTPRequestOperationManager alloc] init]不会出现做。

如果您仍然遇到问题,我建议您添加 Exception Breakpoint以准确识别此异常发生的位置。

关于ios - AFNetworking 无法在 GET 请求上创建请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21115959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com