开发者

Strange Status Code From Apple Receipt Verification Sandbox

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 exception开发者_运维知识库s 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?


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜