This code:
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.cnn.com"]];
[req setHTTPMethod:@"GET"];
NSURLResponse *res;
NSError *err;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];
NSString *html = [NSString stringWithUTF8String:[data bytes]];
NSLog(@"email adress is %@ and password is %@, response is %@, length is %i", self.boxEmail.text, self.boxPassword.text, html, data.length);
Shows null for html. What is going wrong?
NSLog’ing data.description yields:
<3c21444f 43545950 45204854 4d4c3e0a 3c68746d 6c206c61 6e673d22 656e2d55 53223e0a 3c686561 643e0a3c
etc.
You cannot assume the data will be NUL terminated, therefore you should not call
stringWithUTF8String. Use the following:if you are using ARC or:
otherwise.