title: Sending In-App Purchase receipt data to my server
body: <p>I'm implementing receipt validation server side for In-App Purchases, as described by the <a href="https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1" rel="noreferrer" title="Receipt Validation Programming Guide">Receipt Validation Programming guide</a>.</p>
  
  <p>Whenever I try to encode to Base64 the receipt and send it to my server, I get an error from Apple.  But if I manually copy-paste the non-encoded base64 on the server, encode it there and trigger a REST call to Apple, their iTunes server responds correctly.</p>
  
  <p>I'm not sure what am I doing wrong client side.  The code is very straightforward:</p>
  
  <pre><code>-(NSString*) retrieveReceiptFromCompletedTransaction:(SKPaymentTransaction*)transaction
  {
    NSData *receiptData;
    NSString *receiptString;
    NSBundle *bundle = [NSBundle mainBundle];
  
    if ([bundle respondsToSelector:@selector(appStoreReceiptURL)]) {
      NSURL *receiptURL = [bundle performSelector:@selector(appStoreReceiptURL)];
      receiptData= [NSData dataWithContentsOfURL:receiptURL];
    }
    else {
      receiptData = transaction.transactionReceipt;
    }
  
    receiptString = [receiptData base64EncodedStringWithOptions:0];
    return receiptString;
  }
  </code></pre>
  
  <p>Any ideas?</p>