0

actually what I wanna do is just sending a JSONString with a POST-Request to a server and achieve the "OK" in the response's header.

What framework would you suggest for this purpose? I already looked at restkit but it's way too huge for my purpose imo. I would prefer a slim framework/solution.

Thanks in advance

user1066006
  • 135
  • 3
  • 14
  • 1
    [It does not look like you need a framework for that](http://stackoverflow.com/q/4456966/335858): `NSURLRequest` should do the trick. Am I missing anything? – Sergey Kalinichenko Aug 03 '12 at 10:46

1 Answers1

1

doesn't sound like you need a Framework here as @dasblinkenlight has already commented you should probably just use 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;
}
AppHandwerker
  • 1,758
  • 12
  • 22
  • Thank you very much, helped great!! Just one more question: Can I also add the shttp authorization to this code or would I have to use one of the frameworks in this case? – user1066006 Aug 03 '12 at 17:49