afnetworking-2

What is the recommended way to intercept and prevent redirects with AFNetworking 2.0?

纵然是瞬间 提交于 2019-12-06 08:02:51
It seems to me that the proper place to do this is in AFURLSessionManager , in setting the taskWillPerformHTTPRedirection block, but I am unsure of the best way to handle it. Currently, in my AFHTTPSessionManager subclass, I am setting the redirect block globally for all requests, and I know I can prevent redirects by returning nil here: - (void)setupRedirectBlock { [self setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) { return nil; }]; } ...but I need to only do this on specific tasks, and

Upload an sqlite file

元气小坏坏 提交于 2019-12-06 06:58:46
问题 I'm using AFNetworking to try to upload a file: -(void)uploadFile{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"data.sqlite"]; NSURL *filePathURL = [NSURL fileURLWithPath:filePath]; NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http:/

NSURLSession, upload task - Get actual bytes transferred

心不动则不痛 提交于 2019-12-06 03:46:03
问题 I was getting bug reports that my iOS app failed upload of images on slow connections. While my timeout probably wasn't high enough, there was another issue. I found that upload progress quickly went to 100% even though I could see in Charles that bytes were still being transferred. I use the following method of NSURLSession: - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData completionHandler:(void (^)(NSData *data, NSURLResponse *response,

Can AFNetworking 2 store the cookies

拜拜、爱过 提交于 2019-12-05 20:18:27
I used AFHTTPClient and seems it stored cookies in the box. So when I was logged in. and then reload my app, the cookies were in application automatically. Maybe I confused about this. But seems it works in the way I described. Now I use this code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; But when I restart my application I get message with wrong token when I try request some of my

AFNetworking 2.0 - mutable json

别说谁变了你拦得住时间么 提交于 2019-12-05 17:54:21
My code currently looks like this NSURL *URL = [NSURL URLWithString:URLForSend]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"%@", responseObject); [BoxJsonDataHelper gotNewJson:responseObject]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Request Failure Because %@",[error userInfo]);

Link follows when using UIWebView+AFNetworking

落花浮王杯 提交于 2019-12-05 16:43:31
I'm trying out AFNetworking 2.0+'s new UIKit+AFNetworking extension for UIWebView , loadRequest:progress:success:failure: . So far so good, but after the initial request is made, additional requests caused by user interaction falls back to the built-in loadRequest: of plain UIWebView . I'd much prefer that all requests went through the AFNetworking improved one. Preliminary, I'm thinking I should override as much as possible by returning NO in shouldStartLoadWithRequest and call loadRequest:progress:success:failure: manually, but it seems a little heavy-handed. Is this the intended way or am I

Does AFNetworking cache images load automatically or do we have to do it manually?

折月煮酒 提交于 2019-12-05 16:34:29
I'm using AFNetworking to load images from JSON feed. In here, first time when user opens the app, images load from the internet. It's fine. But when user go back and come again from another view, while using the app, images should load from the cache, not from the internet. How can I do that? - (void)loadDetailData { detailPost = nil; NSString *detailUrl = [NSString stringWithFormat:@"%@", self.Details.firsturl]; AFHTTPRequestOperationManager *detailManager = [AFHTTPRequestOperationManager manager]; [detailManager GET:detailUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id

AFHTTPSessionManager - get unserialized/raw response body (NSData?)

我的梦境 提交于 2019-12-05 14:15:09
I've subclassed AFHTTPSessionManager according to the recommended best practice for iOS 8 (in place of AFHTTPOperationManager, which I was using before). I can grab the NSHTTPURLResponse from the task (except that has no body, only headers), and the callback returns the serialized responseObject which is fine. Sometimes I need to log the response as a string or display it in a text field - there doesn't appear to be a way to do this natively using SessionManager? OperationManager allowed you to reference the raw response as an NSString: operation.responseString; I suppose I could stringify the

AFNetworking AFHTTPClient Class

坚强是说给别人听的谎言 提交于 2019-12-05 11:32:45
I’m fairly new to iOS programming, especially when it comes to webservices. I’m developing a App for academic purposes, and I need to communicate with my server, currently using AFNetworking2 and Restler/php, everything work when it comes to GET methods. But I can’t upload anything. Been reading for hours, in github support site, stackoverflow, pretty much all examples/questions to upload images (and there are a LOT) use this line: AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://server"]]; I do have a Client class, subclass of AFHTTPSessionManager, with my

Post request Amazon S3 with AFNetworking

妖精的绣舞 提交于 2019-12-05 08:44:22
I'm posting an image to Amazon S3 via AFNetworking, and getting a strange error. The file is uploading, but once it hits 100% it returns an error: Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: method not allowed (405)" AFAmazonS3Manager *s3manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:AWS_Access_Key secret:AWS_Secret_Key]; s3manager.requestSerializer.region = AFAmazonS3USWest1Region; s3manager.requestSerializer.bucket = AWS_Bucket_Name; //setting for image url name NSString* destionationPathForS3 = @"1234567"; [s3manager postObjectWithFile:self