AFHTTPRequestOperation

AFHTTPRequestOperation

AFNetworking如何发送发布请求字符串?

//restrinBASE64STRING is a NSString ,Program error
[manager POST:URLString parameters:restrinBASE64STRING success:^(AFHTTPRequestOperation *operation, id responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

最佳答案

解决这个问题

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:URLString]];
[request setHTTPMethod:@"POST"];
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[restrinBASE64STRING dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:postBody];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];

operation.responseSerializer = [AFHTTPResponseSerializer serializer];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];
[[NSOperationQueue mainQueue] addOperation:operation];

07-26 09:37