title: NSURLConnection http status 400 , error (null)
body: <p>I am trying to post the data on the server which ask for Json format. here's the requirement of json format that needs to be send to the server</p>
  
  <pre><code>{"storeId":"abc@gmail.com",
   "handleName":"abcd",
  "profilePic":"(encoded bse64image in string)"
  }
  </code></pre>
  
  <p>and response I will get is in json format</p>
  
  <p>Here's what i am doing </p>
  
  <pre><code>- (void)postTo:(NSString *)urlString params:(NSDictionary *)params completion:(void (^)(id, NSError *))completion {
          NSURL *url = [NSURL URLWithString:urlString];
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
      [request setHTTPMethod:@"POST"];    
      if (params.count) {
          NSMutableArray *paramArray = [NSMutableArray array];
          for (NSString *key in [params allKeys]) {
              NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
              NSString *encodedValue = [params[key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
              NSString *encodedPair = [[encodedKey stringByAppendingString:@"="] stringByAppendingString:encodedValue];
              [paramArray addObject:encodedPair];
          }        
          NSString *paramString = [paramArray componentsJoinedByString:@"&amp;"];        
          NSData *data = [paramString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
          [request setHTTPBody:data];
          [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[data length]] forHTTPHeaderField:@"Content-Length"];
          [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
          [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Accept"];
      }
          [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {        
          NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;      
          if (!error &amp;&amp; httpResponse.statusCode &lt; 400) {
              NSError *parseError;
              id parse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&amp;parseError];
              if (!parseError) {
                  completion(parse, nil);
              } else {
                  NSLog(@"parse error %@", parseError);
                  completion(nil, parseError);
              }
          } else {
              NSLog(@"http status %d, error %@", httpResponse.statusCode, error);
              completion(nil, error);
          }
    }];
  </code></pre>
  
  <p>and calling it like this 
     </p>
  
  <pre><code> NSString *storeId=@"abc@gmail.com";
              NSString *handleName = @"abc";
             // NSString *profilePic=@"samplestringtest";
          UIImageView *image= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"abc.jpg"] ];
          _profilepicImageView.image= image.image;
          NSData *imag64 = UIImageJPEGRepresentation(_profilepicImageView.image, 0.5f);
          NSString *encoded = [imag64 base64EncodedStringWithOptions:0];
         NSString *urlString = @"http://server.cloud.com/user/registration";
         NSDictionary *params = @{@"storeId":storeId,
                                 @"handleName":handleName,
                                 @"profilePic":encoded
                                  };
         [self postTo:urlString params:params completion:^(id result, NSError *error) {
              if (!error &amp;&amp; result != nil) {
                
                  NSLog(@"%@", result);
                  HUD.progress = 1.0f;
                  [HUD hide:YES];
                  [self afterSignupProceed];
                  } else {
                  NSLog(@"%@", error);
              }
          }];
  </code></pre>
  
  <p>      
  I am getting http status 400 , error null</p>