title: how to compare a NSURLconnection http response data with a string value in iphone?
body: <p>I want to do an activation module which will send a http request with a PIN number and then read the response. If the response is &quot;OK&quot;, it opens up with a main menu.  The problem is that I am receiving the response as &quot;OK&quot; but I am unable to compare it with a NSString @&quot;OK&quot;.  How to compare the http response with a string?</p>
  <p>Here is  my piece of code:</p>
  <pre><code>-(IBAction) submitPINAction:(id) sender
  {
      printf(&quot;inside submit btn&quot;);
      mydata = [NSMutableData alloc];
      NSURLRequest *request = [NSURLRequest  requestWithURL:
                               [NSURL URLWithString:@&quot;http://192.168.100.3/WWTF/activationApp.php?PIN=11111&quot;]
                               
                                                cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
      NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
      if(connection)
      {
          mydata = [[NSMutableData data] retain];
      }
      else
      {
          //Handle error : Not received data
          printf(&quot;No internet connection&quot;);
      }
  }
  
  
  -(void)connection:(NSURLConnection *)theConnection
     didReceiveData:(NSData *)incrementalData {
      printf(&quot;data received&quot;);
      if (mydata==nil) {
          mydata =
          [[NSMutableData alloc] initWithCapacity:2048];
      }
      [mydata appendData:incrementalData];
      NSString *temp = [[NSString alloc] initWithData:mydata encoding:NSASCIIStringEncoding];
      
      NSString *string1 = @&quot;OK&quot;;
      
      
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
      
      if([string1 isEqualToString:temp]){   // HERE IS THE PROBLEM, THE STRINGS ARE NOT GETTIN COMPARED
      
          [prefs setBool:TRUE  forKey: @&quot;activationKey&quot;];
          // show the main menu
          mainMenuController *mmC = [[mainMenuController alloc]initWithNibName:@&quot;mainMenu&quot; bundle:[NSBundle mainBundle]];
          self.mmainMenuController = mmC;
          [mmC release];
          [self.view addSubview:[mmainMenuController view]];
      }
      else{
          printf(&quot;in else&quot;);
          [prefs setBool:FALSE  forKey: @&quot;activationKey&quot;];
          //show an alert
          UIAlertView *alertActivationFail = [[UIAlertView alloc] initWithTitle:@&quot;Activation Failed!&quot; message:@&quot;PIN is Incorrect&quot; delegate:self cancelButtonTitle:@&quot;OK&quot; otherButtonTitles:nil];
          [alertActivationFail show];
          [alertActivationFail release];
      }
  }
  </code></pre>