标签: afjsonrequestoperation

如何在AFJSONRequestOperation的回调中从NSHTTPURLResponse中获取响应数据?

我有一种情况需要从回调块中访问AFJSONRequestOperation的原始响应数据,该回调块仅包含NSHTTPURLResponse.我能够从NSHTTPURLResponse获取statusCode,但是没有看到任何获取原始数据的方法.有没有人知道从这个操作的故障回调块访问它的好方法?

ios afnetworking afjsonrequestoperation nshttpurlresponse

26
推荐指数
1
解决办法
3万
查看次数

在AFNetworking 2.x中替换AFJSONRequestOperation

按照本教程,我正在制作一个带有HTML请求的基本iPhone应用程序.

本教程让我在AFNetworking中使用AFJSONRequestOperation.问题是,我正在使用AFNetworking版本2,它不再具有AFJSONRequestOperation.

所以,当然,这个代码(从教程的大约一半,在" 查询iTunes Store搜索API " 标题下)不编译:

NSURL *url = [[NSURL alloc]
    initWithString:
    @"http://itunes.apple.com/search?term=harry&country=us&entity=movie"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation =
    [AFJSONRequestOperation JSONRequestOperationWithRequest:request
    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"%@", JSON);
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response,
        NSError *error, id JSON) {
            NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
    }];
[operation start];
Run Code Online (Sandbox Code Playgroud)

我的问题是,我该如何替换AFJSONRequestOperation以便我可以继续使用AFNetworking 2.x?我用谷歌搜索了这一点,发现似乎没有其他人在问这个问题.

objective-c ios afnetworking afjsonrequestoperation afnetworking-2

22
推荐指数
2
解决办法
1万
查看次数

AFNetworking超时

我正在使用AFJSONRequestOperation上传图片.

在上传图像数量的情况下,某些请求因超时错误而失败.

我试过了

AFJSONRequestOperation *operation = ...
[operation start];
Run Code Online (Sandbox Code Playgroud)

AFJSONRequestOperation *operation = ...
[operations addObject:operation];
...
[client enqueueBatchOfHTTPRequestOperations:operations progressBlock:nil completionBlock:nil];
Run Code Online (Sandbox Code Playgroud)

但是,仍然没有运气.

我认为时间计数在创建操作时开始.

那么,我应该为我自己的算法逐个安排请求吗?

timeout httpclient ios afnetworking afjsonrequestoperation

5
推荐指数
1
解决办法
1576
查看次数

AFNetworking版本2内容类型错误

我正在尝试制作一个与特定JIRA服务器交互的iPhone应用程序.我有以下代码登录:

NSURL *url = [[NSURL alloc] initWithString:@"https://mycompany.atlassian.net/rest/auth/latest/session/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"{\"username\":\"%@\",\"password\":\"%@\"}", username, password];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept" ];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:
    ^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"ERROR: %@", error);

    }
 ];
 [operation start];
Run Code Online (Sandbox Code Playgroud)

但它给了我以下与Content-Type有关的错误:

ERROR: Error Domain=AFNetworkingErrorDomain Code=-1011
"Request failed: unsupported media type (415)"
UserInfo=0x8cd6540
{
  NSErrorFailingURLKey=https://mycompany.atlassian.net/rest/auth/latest/session/,
  NSLocalizedDescription=Request failed: unsupported media type …
Run Code Online (Sandbox Code Playgroud)

objective-c ios afnetworking afjsonrequestoperation afnetworking-2

4
推荐指数
1
解决办法
1万
查看次数