afnetworking-2

How do I set a request timeout and cache policy in AFNetworking 2.0?

走远了吗. 提交于 2019-12-03 05:40:11
问题 I'm following the given example code AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; To change the timeout and cache policy I 'hacked' the library and created - (AFHTTPRequestOperation *)GET:

How can I set cookies with AFNetworking 2.0 while uploading image with parameteres?

喜夏-厌秋 提交于 2019-12-03 03:18:29
What if I had to attach a cookie with a post requst? How should I do this? NSURL *URL = [NSURL URLWithString:addAddressUrl]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; // Set cookie too NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"<URL>"]]; NSDictionary *cookiesDictionary = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies]; if(cookiesDictionary) { [request setAllHTTPHeaderFields:cookiesDictionary]; } How to attach this request with AFNetworking call? I have gone through the documents of AFNetworking but

AFNetworking 2 authentication with AFHTTPRequestOperation

家住魔仙堡 提交于 2019-12-03 03:06:07
I want to use AFNetworking with a batch operation. I want to download 3 json files. How to add basic authentication with AFHTTPRequestOperation ? NSMutableArray *mutableOperations = [NSMutableArray array]; for (NSString *fileURL in filesToDownload) { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fileURL]]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation , id responseObject) { NSLog(@"success: %@", operation.responseString); } failure:^

How to automatically refresh expired token with AFOAuth2Manager?

这一生的挚爱 提交于 2019-12-02 23:57:41
I'm writing a small iOS client for a server protected with OAuth2. I'm wondering if is it possible using AFOAuth2Manager [here] auto-refreshing the expired token. The idea is that the logic for refreshing the client when the server responds with a 401, or raise an error when the refresh method returns a 401 should be quite common, so probably it is integrated in some library. I created a subclass of AFOAuth2Manager In this subclass I override this method: - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request success:(void (^)(AFHTTPRequestOperation *operation, id

iOS - Increase timeout for AFHTTPRequestOperationManager

孤街浪徒 提交于 2019-12-02 23:17:06
I'm downloading JSON data from a very slow server. It takes about a minute to get a resoonse from the server. I use AFNetworking library and my code throws "The request timed out" error: NSString *urlString = [NSString stringWithFormat:@"%@/account.do?JSON&sysparm_action=getRecords",baseUrlString]; NSString *login = [[NSUserDefaults standardUserDefaults] objectForKey:@"login"]; NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"]; [manager setRequestSerializer:[AFHTTPRequestSerializer serializer]]; [manager.requestSerializer

AFNetworking 2.0 - use responseObject as NSDictionary

删除回忆录丶 提交于 2019-12-02 22:36:25
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; this is the recommended way to send GET request in AFNetworking 2.0. I want to get the value of a specific key in the json, so I want to use responseObject as NSDictionary . this is what I was trying: NSError *jsonError = nil; NSDictionary *json =

Transition from RestKit to pure AFNetworking 2.0

北城以北 提交于 2019-12-02 20:24:41
I'd been using RestKit for the last two years, but recently I've started thinking about transition from these monolith framework as it seems to be really overkill. Here's my pros for moving forward: There is big need in using NSURLSession for background fetches and RestKit has only experimental branch for transition to AFNetworking 2.0. No actual dates when transition will be finished. (Main Reason) No need for CoreData support in network library as no need for fully functional offline data storage. Having headache with new concept of response/request descriptors as they don't support

How do I set a request timeout and cache policy in AFNetworking 2.0?

回眸只為那壹抹淺笑 提交于 2019-12-02 18:59:32
I'm following the given example code AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; To change the timeout and cache policy I 'hacked' the library and created - (AFHTTPRequestOperation *)GET:(NSString *)URLString parameters:(NSDictionary *)parameters timeoutInterval:(NSTimeInterval)timeoutInterval

AFHTTPRequestOperationManager return data in block

你。 提交于 2019-12-02 10:18:06
I created an APIController in my application that has several methods that call specific api urls and return a model object populated with the result of the api call. The api works with json and up to now my code looks like the following: //Definition: - (MyModel *)callXYZ; - (MyModel *)callABC; - (MyModel *)call123; //Implementation of one: - (MyModel *)callXYZ { //Build url and call with [NSData dataWithContentsOfURL: url]; //Create model and assign data returned by api return model; } Now I want to use the great AFNetworking framework to get rid of that "dataWithContentsOfURL" calls. So I

Uploading image with AFNetworking with null parameter doesn't work

我的未来我决定 提交于 2019-12-02 07:31:06
I want too upload the image to server but got error on doing that I have used following code but don't know whats wrong is in there +(void) HTTPPostImage:(NSString *) stringURL andParameter:(NSData *) imageData andSelector:(SEL) selector andTarget:(id) target{ AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:stringURL]]; // NSData *imageData = UIImageJPEGRepresentation(self.avatarView.image, 0.5); NSDictionary *parameters =NULL; NSString *myUUID = [[NSUUID UUID] UUIDString]; // create a UUID NSLog(@"myUUID%@",myUUID);