Skip to content

Instantly share code, notes, and snippets.

@j796160836
Created March 9, 2014 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j796160836/9450763 to your computer and use it in GitHub Desktop.
Save j796160836/9450763 to your computer and use it in GitHub Desktop.
[iOS] POST取回HTML (UTF-8)
NSURL *URL = [NSURL URLWithString:@"http://example.com/"];
NSString *postString = @"company=Locassa&quality=AWESOME!";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
op.responseSerializer =[AFHTTPResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSString* newStr = [NSString stringWithUTF8String:[responseObject bytes]];
NSString* newStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"HTML: %@", newStr);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[[NSOperationQueue mainQueue] addOperation:op];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment