Created
March 9, 2014 16:58
-
-
Save j796160836/9450763 to your computer and use it in GitHub Desktop.
[iOS] POST取回HTML (UTF-8)
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
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