0

实际上我想做的只是将带有 POST-Request 的 JSONString 发送到服务器并在响应的标头中实现“OK”。

为此,您会建议什么框架?我已经看过restkit,但对于我的目的来说它太大了。我更喜欢苗条的框架/解决方案。

提前致谢

4

1 回答 1

1

听起来你在这里不需要一个框架,因为@dasblinkenlight 已经评论过你可能应该只使用 NSURLRequest。

    -(BOOL)sendRequestToURL:(NSString*)stringURL withJSON:(NSString*)JSONAsAString{
    NSError *jsonERROR =nil;
    __block BOOL success = NO;
    NSOperationQueue* queue = [[NSOperationQueue alloc]init];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:stringURL]];
    request.HTTPMethod = @"POST";
    request.HTTPBody = [NSJSONSerialization dataWithJSONObject:JSONAsAString options:0 error:&jsonERROR];
    if (!jsonERROR){
        [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError * error) {
            NSHTTPURLResponse *httpResonse = (NSHTTPURLResponse*)response;
            if (httpResonse.statusCode == 200 ) {
                success = YES;
            }
        }];
    } else {
        NSLog(@"jsonERROR: %@", jsonERROR.description);
    }
    return NO;
}
于 2012-08-03T11:00:14.123 回答