title: verifying iOS in app purchase receipt with C#
body: <p>I am verifying my ios <code>in app purchase</code> receipt  on my server using <code>C#</code> web service</p>
  
  <p>I got receipt as string by doing below in Xcode:</p>
  
  <pre><code>- (void) completeTransaction: (SKPaymentTransaction *)transaction
  {
      NSString* receiptString = [[NSString alloc] initWithString:transaction.payment.productIdentifier];
  
      NSLog(@"%@",receiptString);
  
      NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
  
      NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
  
      NSString *jsonObjectString = [receipt base64EncodedStringWithOptions:0];
  
  }
  </code></pre>
  
  <p>and I am sending that string(receipt)  to my <code>C#</code> web service as parameter.
  Here is my web service method:</p>
  
  <pre><code>[WebMethod(Description = "Purchase Item Verify")]
  public string PurchaseItem(string receiptData)
   {
      string returnmessage = "";
  
      try
      {
          var json = "{ 'receipt-data': '" + receiptData + "'}";
  
          ASCIIEncoding ascii = new ASCIIEncoding();
          byte[] postBytes = Encoding.UTF8.GetBytes(json);
  
          HttpWebRequest request;
          request = WebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt") as HttpWebRequest;
          request.Method = "POST";
          request.ContentType = "application/json";
          request.ContentLength = postBytes.Length;
  
          Stream postStream = request.GetRequestStream();
          postStream.Write(postBytes, 0, postBytes.Length);
          postStream.Close();
  
          var sendresponse = (HttpWebResponse)request.GetResponse();
  
          string sendresponsetext = "";
          using (var streamReader = new StreamReader(sendresponse.GetResponseStream()))
          {
              sendresponsetext = streamReader.ReadToEnd();
          }
          returnmessage = sendresponsetext;
  
      }
      catch (Exception ex)
      {
          ex.Message.ToString();
      }
      return returnmessage;
  }
  </code></pre>
  
  <p>It always return  <code>{"status":21002}</code>.
  I have been searching for two days , but still can't find out the solution. Can someone help me, what am i wrong ? </p>
  
  <p>**I am testing on sandbox that is why i use sandbox URL. I can verify the transaction receipt within my app.</p>