afnetworking-2

(Cocoa error 3840.)\" (Invalid value around character 0.) AFNetworking

人盡茶涼 提交于 2019-11-30 04:26:17
I've been getting the following error when using the GET method to retrieve a file from a server: Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x16e81ed0 {NSDebugDescription=Invalid value around character 0.} I've tried a number of different things and I believe it could be something to do with the JSON format on the file that I'm trying to get. Here is the code I've been using: _username = @"JonDoe"; NSDictionary *parameters = @{ @"username" : _username}; AFHTTPRequestOperationManager

Upload an image with AFNetworking 2.0

不打扰是莪最后的温柔 提交于 2019-11-30 03:57:06
I can't understand why this is so hard. All the tutorials and articles online seem to be talking about the 1.0 api, which is pretty useless. I've tried a few different ways and get different results. What am I doing wrong? upload task - this seems to not be using a multipart form, wtf? NSMutableURLRequest *request = [self.manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:url relativeToURL:[NSURL URLWithString:ApiBaseUrl]] absoluteString] parameters:@{} constructingBodyWithBlock:nil]; NSProgress *progress; NSURLSessionUploadTask *task = [self

AFNetworking 2.0 - “unacceptable content-type: text/plain”

主宰稳场 提交于 2019-11-30 03:19:58
I'm using AFNetworking 2.0 to read JSON from a service I'm building (on localhost for now) in Node. Pretty normal stuff. Node is sending JSON like so: res.setHeader('Content-Type','application/json'); res.end( JSON.stringify(...)); My iOS first-pass code is attempting to read that data like so: typedef void(^NextBlock)(); AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager GET:self.newestTimestampURL.absoluteString parameters:nil success:^(AFHTTPRequestOperation *operation, id

AFNetworking 2.0 and use cache only when offline

狂风中的少年 提交于 2019-11-30 00:14:47
问题 I have a problem when users use my app and they lost connection or use airplane mode. My app server side doesn't set any cache policy and for the time being I can't change it. I migrated from AFNetworking 1.x to 2.0 and now I'm using AFHTTPRequestOperationManager when making requests. The problem is that because I have no cache policy on the server side, every request is made to the server (which for now is fine) but if the user is not able to connect to my server, it doesn't load the cached

How can I log each request/response using Alamofire?

牧云@^-^@ 提交于 2019-11-29 22:47:59
Is there a way to log each request / response using Alamofire (something similar to AFNetworkActivityLogger) ? I am aware of Printable, DebugPrintable and Output (cURL) but they are not quite what I am looking for. Something like this might be what you were looking for: extension Request { public func debugLog() -> Self { #if DEBUG debugPrint(self) #endif return self } } Usage: Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"]) .debugLog() .response {…} If you want to print all responses, you could write your own response method, similar to the responseObject()

AFNetworking 2: How to cancel a AFHTTPRequestOperationManager request?

我的未来我决定 提交于 2019-11-29 21:19:37
I migrated my networking functionality from AFNetworking to AFNetworking v2 and instead of AFHttpClient I am using AFHTTPRequestOperationManager to support iOS6 as well. My issue is that while in AFHttpClient there was the functionality to cancel a pending request using the - (void)cancelAllHTTPOperationsWithMethod:(NSString *)method path:(NSString *)path; method, in the AFHTTPRequestOperationManager there is no such obvious method. What I've done up to now is subclassing AFHTTPRequestOperationManager and declaring an iVar AFHTTPRequestOperation *_currentRequest; When I make a request the code

AFNetworking 500 response body

妖精的绣舞 提交于 2019-11-29 19:05:13
问题 I've been using AFNetworking 2.0 in my app. I've noticed that if my web-service returns a 500 status code I do not get the body of the response. Here is an example of my php code try { $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); return $conn; } catch( PDOException $e ) { $response->status(500); echo( "Connection Error: " . $e->getMessage() ); } If I use a simple rest client this is an example

AFHTTPRequestOperationManager post multi-part request not working

亡梦爱人 提交于 2019-11-29 17:09:22
Here is the template that I am using from the Git Doc AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; [manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; Here is how I am using it -(void)postMultipartToServer { if (!self.destinationUrl) { return; } AFHTTPRequestOperationManager *manager =

Unable to use self signed certificate with AFNetworking 2

你离开我真会死。 提交于 2019-11-29 15:41:29
问题 I put the .cer certificate used by the Apache Server in the Xcode project. When the app tries to talk to the server I get this error in Xcode: Assertion failure in id AFPublicKeyForCertificate(NSData *__strong)(), /Users/../ProjectName/AFNetworking/AFSecurityPolicy.m:52 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: allowedCertificate' Here is the code for calling the server : AFHTTPRequestOperationManager *manager

POST request with AFNetworking 2.0 - AFHTTPSessionManager

非 Y 不嫁゛ 提交于 2019-11-29 14:42:02
问题 Hej, I am struggling with doing a POST request to the parse REST API. I am using AFNetworking 2.0. My code for the AFHTTPSessionManager Subclass looks as follows: + (ParseAPISession *)sharedSession { static ParseAPISession *sharedSession = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedSession = [[ParseAPISession alloc] initWithBaseURL:[NSURL URLWithString:kSDFParseAPIBaseURLString]]; }); return sharedSession; } And: - (id)initWithBaseURL:(NSURL *)url { self =