Forked from okitsutakatomo/AFTextResponseSerializer.h
Last active
December 26, 2015 21:19
-
-
Save kyle-go/7215103 to your computer and use it in GitHub Desktop.
AFNetworking2.0Request failed: unacceptable content-type: text/plain解决方法 ref: http://qiita.com/okitsutakatomo/items/21b126fb1e3dae3bcb2f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AFURLResponseSerialization.h" | |
@interface AFTextResponseSerializer : AFHTTPResponseSerializer | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AFTextResponseSerializer.h" | |
@implementation AFTextResponseSerializer | |
+ (instancetype)serializer { | |
AFTextResponseSerializer *serializer = [[self alloc] init]; | |
return serializer; | |
} | |
- (instancetype)init { | |
self = [super init]; | |
if (!self) { | |
return nil; | |
} | |
self.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"text/plain", nil]; | |
return self; | |
} | |
#pragma mark - AFURLResponseSerialization | |
- (id)responseObjectForResponse:(NSHTTPURLResponse *)response | |
data:(NSData *)data | |
error:(NSError *__autoreleasing *)error | |
{ | |
if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) { | |
if ([(NSError *)(*error) code] == NSURLErrorCannotDecodeContentData) { | |
return nil; | |
} | |
} | |
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request failed: unacceptable content-type: text/plain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oauth_callback_confirmed=true&oauth_token=XXXXXXXXXX-XXXXXXXXXX&oauth_token_secret=XXXXXXXXXXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
// AFTextResponseSerializerをResponseSerializerに設定する。 | |
AFTextResponseSerializer *textSerializer = [AFTextResponseSerializer serializer]; | |
[manager setResponseSerializer:textSerializer]; | |
[manager GET:baseUrl parameters:signedParams success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSLog(@"Response: %@", responseObject); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
NSLog(@"Error: %@", error); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment