Lucas Veiga
Lucas Veiga

Reputation: 1795

NSHTTPURLResponse

Hey everbody, i'm trying to treat the response of a http post. My php is giving a simple message, so, how can i treat it? I mean, if gives me the "Error" message, do something, or "OK" do another thing.

NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[NSError alloc] init];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
    NSLog(@"Response: %@", result);

}
if (result == @"Logged") {
    NSLog(@"OK");
}
if (result == @"Error") {
    NSLog(@"No");
}

Thanks!

Upvotes: 1

Views: 5449

Answers (1)

Matt Williamson
Matt Williamson

Reputation: 40193

Try the isEqualToString: method. E.g.:

if ([result isEqualToString:@"Logged"]) {
    NSLog(@"OK");
} else if ([result isEqualToString:@"Error"]) {
    NSLog(@"No");
}

Upvotes: 3

Related Questions