I got from server a response :
[NSURLConnection
sendAsynchronousRequest:request
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error)
{
if ([data length] >0 && error == nil)
{
NSLog(@"DATA1: %@",data);
NSString *content;
content = [NSString stringWithUTF8String:[data bytes]];
NSLog(@"DATA2: %@",content);
something is strange here. the second NSLOG shows me a null data- but if the data is null how could he pass the if statement ?
the first log show me: <636f6e66 69726d65 64> .
I have to say that sometimes it do work ! it depend on the values somehow …
Because the with first log, you’re printing the
NSDatainstance, and with the second, theNSStringyou want to generate from the data. But if the data is not valid UTF-8 (which may be the case, since it’s not NUL-terminated, andstringWithUTF8String:requires a NUL-terminated string, so it doesn’t stop at the end and it might read garbage), then it returnsnil.What you want is: