【发布时间】:2014-08-09 05:48:46
【问题描述】:
我正在尝试使用 AFNetworking 使用 http 正文执行 POST 请求。我用this post's回答
NSString *urlString = [NSString stringWithFormat:@"my-url"];
NSString *parameterData = [NSString stringWithFormat:@"request_type=get_story_nids&story_type=%@&story_number=%@", section, count];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[parameterData dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id result) {
completionBlock(nids,nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
completionBlock(nil, error);
}];
我在操作 setCompletionBlockWithSuccess 的完成块中放置了断点,它甚至没有命中它。
如果有帮助,做
NSMutableData* result = [[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error] mutableCopy];
有效并为我提供正确的数据。
有什么想法吗?
【问题讨论】:
标签: ios objective-c post nsurlrequest afnetworking-2