1

我向收据验证地址发出 base64 编码数据的 post 请求,如下所示(这是在 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();

我很确定事情的格式是正确的,因为我没有从苹果收据验证端点得到任何异常。我得到的全部回复是

{状态:-42352}

而且我在任何地方都找不到这个错误的含义。有谁知道这意味着什么,或者我的代码是否有错误?

4

1 回答 1

3

刚刚解决了同样的问题。从这里得到解决方案:验证应用内购买的收据

问题出在后期编码中。当我使用在我的服务器上编码帖子时

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

我有相同的 -42352 状态。当我在 iPhone 上使用我自己的函数进行编码时 - 一切正常!魔法...

于 2011-06-15T11:53:08.663 回答