Verifying iOS in app purchase receipt with C# getting same result 21002

Viewed 30
public int PurchaseItem(string receiptData)
        {
          
            int proUserStatus = 1;
            try
            {
                // var json = "{ 'receipt-data': '" + receiptData + "'}";
                var json = new JObject(new JProperty("exclude-old-transactions", true, "password", "xyz", "receipt-data",receiptData)).ToString();
                ASCIIEncoding ascii = new ASCIIEncoding();
                byte[] postBytes = Encoding.UTF8.GetBytes(json);
                //  HttpWebRequest request;
                var request = System.Net.HttpWebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt"]);
                request.Method = "POST";
                request.ContentType = "application/json";
                request.ContentLength = postBytes.Length;
                
                //Stream postStream = request.GetRequestStream();
                //postStream.Write(postBytes, 0, postBytes.Length);
                //postStream.Close();

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(postBytes, 0, postBytes.Length);
                    stream.Flush();
                }
                //  var sendresponse = (HttpWebResponse)request.GetResponse();
                var sendresponse = request.GetResponse();
                string sendresponsetext = "";
                using (var streamReader = new StreamReader(sendresponse.GetResponseStream()))
                {
                    sendresponsetext = streamReader.ReadToEnd().Trim();
                }
                ValidateResponse vres = JsonConvert.DeserializeObject<ValidateResponse>(sendresponsetext);
                proUserStatus = vres.status;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return proUserStatus;
        }

It always return {"status":21002}. Why is this so? I am testing on a sandbox which is why I use the sandbox URL.

0 Answers
Related