afnetworking-2

Afnetworking 2.0 parameter encoding

泪湿孤枕 提交于 2019-12-11 11:28:18
问题 Hi i am using afnetworking 2.0 in my project. I need to post with json dic as parameter. In earlier version afhttpclient there is AFJSONParameterEncoding. How to do it in latest version? 回答1: Right now you need to use serializer classes for your reuqest manager AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager

Getting variable from the inside of block [duplicate]

試著忘記壹切 提交于 2019-12-11 09:15:35
问题 This question already has answers here : How do I return a variable from a block inside a method? (3 answers) AFHTTPRequestOperationManager return data in block (1 answer) Closed 5 years ago . I'm using AFNetworking 2 to GET data from server and I need to get back the responseObject but no matter what I do i still get <null> . Here is the method which is sending GET request to server and in response it gets NSDictionary which I want to use in another method... - (void

How to make a HTTP persistent connection with server using AFNetworking library

岁酱吖の 提交于 2019-12-11 07:24:52
问题 Can anyone please point me in the right direction in making a HTTP persistent connection with server using AFNetworking library. I've already looked at the following code: NSURL *URL = [NSURL URLWithString:@"http://example.com"]; AFRocketClient *client = [[AFRocketClient alloc] init]; [client SUBSCRIBE:@"/resources" usingBlock:^(NSArray *operations, NSError *error) { for (AFJSONPatchOperation *operation in operations) { switch (operation.type) { case AFJSONAddOperationType: [resources

UIImageView+AFNetworking setImageWithURLRequest uses RestKit?

孤街浪徒 提交于 2019-12-11 04:55:29
问题 I am using RestKit (0.20.0) for my Rest Api implementation - all the GETs, POSTs etc. The GETs return some urls for the images. I am using UIImageView+AFNetworking setImageWithURLRequest function to download these. I was surprised to see RestKit logs getting printed for these fetches so I did some debugging. It seems that some notification is sent by AFNetworking that eventually lands on RestKit. Looks like its happening because AFNetworkingOperationDidStartNotification is fired for the fetch

How to convert AFNetworking service invoke to use AFHTTPSessionManager

☆樱花仙子☆ 提交于 2019-12-11 03:28:26
问题 This is my current call to (asmx) SOAP web service: NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<soap:Body>" "<Save xmlns=\"http://www.myapp.com/\">" "<par1>%i</par1>" "<par2>%@</par2>" "<par3>%@</par3>" "</Save>" "</soap:Body>" "</soap:Envelope>", par1, par2,

Memory warning while downloading file with AFNetworking

南楼画角 提交于 2019-12-11 02:39:54
问题 Update: I wrote a very simple download code: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://xxxx.s3.amazonaws.com/products/ipad/xxxx.mp4"]]; for(int i=0; i<4; i++){ NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,[NSString stringWithFormat:@"xxxx%d.mp4",i]];

AFNetworking 2 - Image upload - Request failed: unsupported media type (415)

偶尔善良 提交于 2019-12-10 21:07:31
问题 I know this question was answered multiple times, but I tried all the answers with no luck. I don't think that I do something fundamentally wrong but something goes definitely wrong here. I use the following code to upload PNG files to tinypng.com. As far as I can see the upload itself works, but I receive the error message: Request failed: unsupported media type (415) The images I use are loaded as JPEG, then resized and transformed to PNG format. The saved files are fine. Now I want send

AFNetworking's setImageWithURLRequest sets image in wrong cell after scroll (iOS, Swift)

拟墨画扇 提交于 2019-12-10 20:49:49
问题 I use table with dequeueReusableCellWithIdentifier and afnetworking+uiimageview . Some of my cells have images, some haven't. If I scroll my table before an image has loaded, success block will put image in reused wrong cell. For example image was in cell #2, but after scroll it appears in cell number #8 because #8 was on second position in that moment. Is it possible to use setImageWithURLRequest with dequeueReusableCellWithIdentifier together? My code: let cell = tableView

POST request with JSON body AFNetworking 2.0

限于喜欢 提交于 2019-12-10 17:28:41
问题 Is there anyway to send a POST request with a JSON body using AFNetworking ~> 2.0? I have tried using: manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager POST:<url> parameters: @{@"data":@"value"} success: <block> failure: <block>' but it doesn't work. Any help is greatly appreciated. Thanks 回答1: You can add your JSON body in NSMutableURLRequest not direct in parameters: . See my sample code : NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; //

How to set HTTP request using AFNetworking 2?

情到浓时终转凉″ 提交于 2019-12-10 16:28:08
问题 I need to send ordinary HTTP request (GET) and answer will in text/html. How can I send this response using AFNetworkin 2 ? Now I'm trying to use NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://example.com"]]; [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; And