views:

85

answers:

1

I am trying to make a simple url call. I cannot convert the bytes into NSString. Following is my code. I get this in my console message; data received from url: †F»∞

-(void)buttonClicked{

NSLog(@"Hello Login clicked..."); NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:@"http://www.apple.com/contact/"]];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setTimeoutInterval:60.0];

    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"data received from url: %s", data);

}

+2  A: 

Don't use the %s modifier when logging. That's for printing char* strings, which an NSString is most definitely not. Use the %@ modifier instead. That's specifically for printing Objective-C objects (like an NSString).

Dave DeLong
thanks a lot, you saved my day.
dipu
Now, accept his answer. ;)
Wevah