title: Java and AppStore receipt verification
body: <p>I am trying to verify a payment receipt on server side. 
  I am getting a <code>{"status":21002, "exception":"java.lang.IllegalArgumentException"}</code> in return</p>
  
  <p>Here is the code:</p>
  
  <pre><code>private final static String _sandboxUriStr = "https://sandbox.itunes.apple.com/verifyReceipt";
  
  public static void processPayment(final String receipt) throws SystemException
  {
      final BASE64Encoder encoder = new BASE64Encoder();
      final String receiptData = encoder.encode(receipt.getBytes());
  
  
      final String jsonData = "{\"receipt-data\" : \"" + receiptData + "\"}";
  
      System.out.println(receipt);
      System.out.println(jsonData);
  
      try
      {
          final URL url = new URL(_sandboxUriStr);
          final HttpURLConnection conn = (HttpsURLConnection) url.openConnection();
          conn.setRequestMethod("POST");
          conn.setDoOutput(true);
          final OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
          wr.write(jsonData);
          wr.flush();
  
          // Get the response
          final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null)
          {
              System.out.println(line);
          }
          wr.close();
          rd.close();
      }
      catch (IOException e)
      {
          throw new SystemException("Error when trying to send request to '%s', %s", _sandboxUriStr, e.getMessage());
      }
  }
  </code></pre>
  
  <p>My receipt looks like this:</p>
  
  <pre><code>{\n\t"signature" = "[exactly_1320_characters]";\n\t"purchase-info" =
  "[exactly_868_characters]";\n\t"environment" = "Sandbox";\n\t"pod" =
  "100";\n\t"signing-status" = "0";\n}
  </code></pre>
  
  <p>Receipt data with a BASE64 encoded receipt looks like this:</p>
  
  <pre><code>{"receipt-data" : "[Block_of_chars_76x40+44=3084_chars_total]"}
  </code></pre>
  
  <p>Does someone have an Idea, or sample code how can I get from receipt string to reply JSON, mentioned <a href="http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html#//apple_ref/doc/uid/TP40008267-CH104-SW1" rel="noreferrer">here</a>?</p>