title: Send POST request with special characters iOS
body: <p>My app calls a web service to login. Usually the service works without any problems, but when I've a password with a special characters (example: !*'\"();:@&amp;=+$,/?%#[]%), the web server doesn't allow me to login because on server side I receive the password without special characters for example:</p>
  
  <p>password insert on my app:      <code>test+test</code></p>
  
  <p>password receive to web server: <code>testtest</code></p>
  
  <p>As you see the request delete the special characters actually I'm sending the login credential by using the following code:</p>
  
  <pre><code>- (id)sendRequestToURL:(NSString *)url withMethod:(NSString *)method withUsername:(NSString*)username withPassword:(NSString*)password andInstallationId:(NSString*)installationId {
      NSURL *finalURL = [[NSURL alloc]init];
  
      if ([method isEqualToString:@"POST"]) {
          finalURL = [NSURL URLWithString:url];
      } else {
          NSLog(@"Metodo no previsto");
      }
  
      NSString *post = [NSString stringWithFormat:@"username=%@&amp;password=%@&amp;installationId=%@", username, password, installationId];
      NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
  
      NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)postData.length];
  
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
      [request setURL:finalURL];
      [request setHTTPMethod:method];
      [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
      [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
      [request setHTTPBody:postData];
  
      NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
      if (connection) {
          [connection start];
      }
  
      return connection;
  }
  </code></pre>
  
  <p>How I can fix this issue? I looked at the <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instm/NSString/stringByAddingPercentEncodingWithAllowedCharacters:" rel="nofollow">NSString class reference</a>, I saw there's the method <code>- stringByAddingPercentEncodingWithAllowedCharacters:</code> to don't delete the special characters, does anyone know how to use this method? Can you show me a code snippet?</p>
  
  <p>Thank you</p>