1

I make a post request of base64 encoded data to the receipt verification address as follows (this is in C#):

        var postSerializer = new JavaScriptSerializer();
        byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(Receipt);
        string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);

        var temp = new Dictionary<string, string>();

        temp.Add("receipt-data", returnValue);

        string jsonReceipt = postSerializer.Serialize(temp);
        request.Method = "POST";
        request.ContentType = "application/json";

        byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(jsonReceipt);



        request.ContentLength = postBytes.Length;
        Stream dataStream = request.GetRequestStream();

        // Write the data to the request stream.
        dataStream.Write(postBytes, 0, postBytes.Length);
        // Close the Stream object.
        dataStream.Close();
        WebResponse response = request.GetResponse();
        // Display the status.
        Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        // Get the stream containing content returned by the server.
        dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();

I'm pretty sure things are in the right format because I'm not getting any exceptions back from the apple receipt verification endpoint. The entirety of the response I get back is

{status : -42352}

And I can't find out what this error means anywhere. Does anyone know what this means or if there's an error in my code?

1 Answers1

3

Just solved the same problem. Got the solution from here: Verify receipt for in App purchase

The problem was in post encoding. When I encoded post on my server using

$receipt = json_encode(array("receipt-data" => base64_encode($receiptdata)));

I had the same -42352 status. When I used my own function for encoding on iPhone - everything worked! Magic...

Community
  • 1
  • 1
deko
  • 2,534
  • 3
  • 34
  • 48
  • Yeah, I'm not sure if it's the way I was sending the data from my app to my PHP service, but sending the base64 encoded string from the app and instead of encoding it in the service did the trick. – adjwilli Jun 28 '12 at 12:09