码迷,mamicode.com
首页 > 移动开发 > 详细

iOS post请求设置请求头

时间:2015-05-04 11:55:50      阅读:437      评论:0      收藏:0      [点我收藏+]

标签:ios http请求头

-(id)executeByOperationManager
{
    AFHTTPRequestOperationManager *manager = [self afnetworkOperationManager];
    
    AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    manager.requestSerializer = requestSerializer;

    manager.securityPolicy.allowInvalidCertificates=YES;
    manager.responseSerializer.acceptableContentTypes =
        [NSSet setWithObjects:@"text/html",@"text/json", nil];
    
    AFHTTPRequestOperation *operation = [manager POST:(NSString *)[self getUrl]
                                        parameters:[self getBodyParam]
                                        success:^(AFHTTPRequestOperation *operation, id responseObject){
                                            [self onRequestSuccess:responseObject];
                                            [self invokeComplete];
                                        }
                                        failure:^(AFHTTPRequestOperation *operation, NSError *error){
                                            if (operation.responseObject) {
                                                [self onRequestSuccess:operation.responseObject];
                                            }else{
                                                [self onRequestFailed:error];
                                            }
                                            [self invokeComplete];
                                        }];
    


    [operation start];
    return operation;
}

iOS post请求设置请求头

标签:ios http请求头

原文地址:http://blog.csdn.net/darongzi1314/article/details/45478231

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!