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

前端 未结 7 1763
深忆病人
深忆病人 2020-12-28 15:12

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

相关标签:
7条回答
  • 2020-12-28 16:02
    NSURL *url = [NSURL URLWithString:RSS_WORLD_NEWS];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    
    // Make sure to set the responseSerializer correctly
    operation.responseSerializer = [AFXMLParserResponseSerializer serializer];
    
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/rss+xml"];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    
        NSXMLParser *XMLParser = (NSXMLParser *)responseObject;
        [XMLParser setShouldProcessNamespaces:YES];
    
         XMLParser.delegate = self;
         [XMLParser parse];
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving contents"
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    
    }];
    
    [operation start];
    

    work for me

    0 讨论(0)
提交回复
热议问题