Tag: afnetworking

AFHTTPSessionManager头

我试图通过设置HTTPAdditionalHeaders设置“Content-Type”的默认标题。 当我查看请求标题时,AFNetworking(v 2.0.3)将其改回。 我也尝试通过setValue:forHTTPHeaderField在requestSerializer上设置标题,但没有成功。 我错过了什么? 更新 NSURL *URL = [NSURL URLWithString:@"http://example.com/api"]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; configuration.HTTPAdditionalHeaders = @{@"Content-Type": @"multipart/form-data"}; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:URL sessionConfiguration:configuration]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; NSMutableDictionary *params = [[NSMutableDictionary alloc]init]; [params setValue:@"some value" forKey:@"someKey"]; [manager POST:@"search" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { NSLog(@"success"); } failure:^(NSURLSessionDataTask *task, NSError *error) { […]

将AFIncrementalStore与Auth令牌一起使用

我正在为App.net的iOS客户端工作,我想使用AFIncrementalStore将Web服务与我的Core Data实现同步到应用程序中。 我已经得到了这两个工作API请求,不需要身份validation令牌,但我不知道如何使用身份validation令牌与AFIncrementalStore。 换句话说,我能够拉下全球的饲料,因为它不需要授权: https://alpha-api.app.net/stream/0/posts/stream/global …但是,要获得用户的stream,你需要auth(你会注意到这个链接给出了一个错误): https://alpha-api.app.net/stream/0/posts/stream 我知道我需要追加一个auth_token API调用的结尾,但我不知道如何使用AFIncrementalStore做到这一点。 更新:这是当前获取全局stream的代码块: 这是从AFIncrementalStore中包含的示例App.net项目直接拉取的方法。 -(NSURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest withContext:(NSManagedObjectContext *)context { NSMutableURLRequest *mutableURLRequest = nil; if ([fetchRequest.entityName isEqualToString:@"Post"]) { mutableURLRequest = [self requestWithMethod:@"GET" path:@"stream/0/posts/stream/global" parameters:nil]; } return mutableURLRequest; }

AFNetworking 2.0请求w。 自定义标题

我试图避免在这里问这样一个新问题,但我是一个Android开发学习IOS,我不能找出我的生活如何使用AFNetworking 2.0添加一个简单的头到我的发布请求。 下面是我的代码到目前为止工作,如果我想做一个请求,不需要一个头。任何人都可以通过添加到我的代码片段或提供一个替代这样做吗? 我遇到了这个问题: http ://www.raywenderlich.com/30445,显示如何添加一个标题下的“一个RESTful类”标题,但它的networking1.0,现在折旧,据我所知。 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"uid": @"1"}; AFHT [manager POST:@"http://myface.com/api/profile/format/json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { //NSLog(@"JSON: %@", responseObject); self.feedArray = [responseObject objectForKey:@"feed"]; [self.tableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); } ]; }

AFNetworking 2.0 – 如何下载asynchronous

在使用AFNetworking 2.0的ios中,我怎样才能轻松地asynchronous下载一个远程镜像,并将其caching到相同url的未来请求中? 我正在寻找一个方便的方式来接收错误callback和成功的。 谢谢

AFNetworking 2.0多部分请求主体空白

类似于这个问题 。 使用AFNetworking 2.0.3并尝试使用AFHTTPSessionManager的POST + constructBodyWithBlock上传图像。 由于未知的原因,似乎HTTP请求正文向服务器发送时总是空白。 我在下面的子类AFHTTPSessionManager(因此使用[self POST …] 。 我试过两种方式来构build请求。 方法1 :我只是试图通过参数,然后添加图像数据,如果它存在。 – (void) createNewAccount:(NSString *)nickname accountType:(NSInteger)accountType primaryPhoto:(UIImage *)primaryPhoto { NSString *accessToken = self.accessToken; // Ensure none of the params are nil, otherwise it'll mess up our dictionary if (!nickname) nickname = @""; if (!accessToken) accessToken = @""; NSDictionary *params = @{@"nickname": nickname, […]

CocoaPods UIImageView + AFNetworking.h无法识别的select器setImageWithURLRequest

我在Xcode 5上安装了使用CocoaPods的AFNetworking 2.1.0 。 //ViewController.h #import <AFNetworking/AFNetworking.h> #import <AFNetworking/UIImageView+AFNetworking.h> 在UIImageView上调用setImageWithURLRequest应用程序失败,并显示以下日志: 这是错误日志: 2014-02-07 11:55:19.984 OPS[1717:60b] *** Terminating app due to uncaught exception'NSInvalidArgumentException', reason: '-[UIImageViewsetImageWithURLRequest:placeholderImage:success:failure:]: unrecognized selector sent to instance 0x147b06d0' 我在这个问题上发现了一些讨论,但提供的解决scheme(join-ObjC -all_load )在我的情况下不起作用。 任何想法? 谢谢

用于iOS 8扩展的AFNetworking后台会话configuration

我目前正在开发一个iOS 8的应用程序扩展,并有这个最后一块的困难。 在我的应用程序的其余部分中,我使用了一个AFHTTPSessionManager子类,我像这样实例化: + (MYAPIClient *)sharedClient { static MYAPIClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedClient = [[MYAPIClient alloc] initWithBaseURL:[NSURL URLWithString:kMYBaseURL]]; _sharedClient.requestSerializer = [[MYAPIRequestSerializer alloc] init]; _sharedClient.responseSerializer = [[MYAPIResponseSerializer alloc] init]; }); return _sharedClient; } 当我使用这个普通的API客户端时,只是发布一些文本forms的共享扩展工作得很好,它甚至有时对图像有效(通常会失败),但我知道我需要使用后台会话configuration。 所以我做了一个非常类似的API客户端,像这样的背景configuration设置: + (MYAPIClient *)sharedBackgroundClient { static MYAPIClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSURLSessionConfiguration *sessionConfiguration […]

如何使用AFOAuth2Manager自动刷新过期的标记?

我正在为使用OAuth2保护的服务器编写一个小型的iOS客户端。 我想知道是否有可能使用AFOAuth2Manager [这里]自动刷新过期的标记。 这个想法是,当服务器响应401时刷新客户端的逻辑,或刷新方法返回401时产生错误的逻辑应该是相当常见的,所以可能将其集成到某个库中。

AFNetworking上传图像

我看了几个例子,但我认为我的问题可能是在PHP中。 我试图从iphone上使用AFNetworking从图像上传到服务器。 这是我的obj-c代码: -(IBAction)uploadButtonClicked:(id)sender { NSData *imageToUpload = UIImageJPEGRepresentation(mainImageView.image, 90); AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://www.THESERVER.com"]]; NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"/PROJECT/upload.php" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFileData: imageToUpload name:@"file" fileName:@"temp.jpeg" mimeType:@"image/jpeg"]; }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *response = [operation responseString]; NSLog(@"response: [%@]",response); [MBProgressHUD hideHUDForView:self.view animated:YES]; […]

APPLE MACH-O LINKED ERROR添加AFNetworking后

只需在我的项目中添加AFNetworking,在B&R之后,我得到如下错误: Undefined symbols for architecture i386: "_SecCertificateCopyData", referenced from: -[AFURLConnectionOperation connection:willSendRequestForAuthenticationChallenge:] in AFURLConnectionOperation.o "_SecCertificateCreateWithData", referenced from: ___44+[AFURLConnectionOperation pinnedPublicKeys]_block_invoke in AFURLConnectionOperation.o "_SecPolicyCreateBasicX509", referenced from: ___44+[AFURLConnectionOperation pinnedPublicKeys]_block_invoke in AFURLConnectionOperation.o -[AFURLConnectionOperation connection:willSendRequestForAuthenticationChallenge:] in AFURLConnectionOperation.o "_SecTrustCopyPublicKey", referenced from: ___44+[AFURLConnectionOperation pinnedPublicKeys]_block_invoke in AFURLConnectionOperation.o -[AFURLConnectionOperation connection:willSendRequestForAuthenticationChallenge:] in AFURLConnectionOperation.o "_SecTrustCreateWithCertificates", referenced from: ___44+[AFURLConnectionOperation pinnedPublicKeys]_block_invoke in AFURLConnectionOperation.o -[AFURLConnectionOperation connection:willSendRequestForAuthenticationChallenge:] in AFURLConnectionOperation.o "_SecTrustEvaluate", referenced […]