D'envoyer des données POST JSON web service via iOS

Je veux transmettre des données POST JSON web service à l'aide du code ci-dessous.

NSString *urlString = @"http://3.10.204.99:9090/service/outage/data/getShortFormData";
NSDictionary *inputData = [[NSDictionary alloc] initWithObjectsAndKeys:
                           @"1020", @"outageId",
                           @"Alex", @"customerName",
                           nil];

NSError *error = nil;
NSData *jsonInputData = [NSJSONSerialization dataWithJSONObject:inputData options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonInputString = [[NSString alloc] initWithData:jsonInputData encoding:NSUTF8StringEncoding];
[self checkWithServer:urlString jsonString:jsonInputString];    

-(void)checkWithServer:(NSString *)urlname jsonString:(NSString *)jsonString{

    NSURL *url1 = [NSURL URLWithString:urlname];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLResponse *response;
    NSError *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    id jsonResponseData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];

    NSDictionary *jsonResponseDict;
    if ([jsonResponseData isKindOfClass:[NSDictionary class]]) {
        jsonResponseDict = jsonResponseData;
    } else {
        //Error-handling code
    }
    jsonResponseData = [jsonResponseDict objectForKey:@"d"];
    if (jsonResponseData == nil) {
        //Server may have returned a response containing an error
        //The "ExceptionType" value is returned from my .NET server used in sample
        id jsonExceptioTypeData = [jsonResponseDict objectForKey:@"ExceptionType"];
        if (jsonExceptioTypeData != nil) {
            NSLog(@"%s ERROR : Server returned an exception", __func__);
            NSLog(@"%s ERROR : Server error details = %@", __func__, jsonResponseDict);
        }
    }
}

Lors de l'exécution de ce code,il ne donne pas d'erreur, mais les données n'est pas mise à jour.

Toute aide sur ce sera regretté.

Merci à vous tous.

OriginalL'auteur user2959571 | 2013-11-06