我一直得到21002&java; Lang.lang.NullPointerException' Apple尝试在沙盒中测试应用内购买时出现的错误。这就是我所做的:
NewtonSoft.Json
并手动完成)并将JSON发送给Apple: var json = "{ 'receipt-data': '" + receipt + "'}";
OR:
var json = new JObject(new JProperty("receipt-data", receipt)).ToString();
然后:
var webRequest = System.Net.HttpWebRequest.Create("https://sandbox.itunes.apple.com/verifyReceipt");
webRequest.ContentType = "text/plain";
webRequest.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(receipt);
webRequest.ContentLength = byteArray.Length;
using (var stream = webRequest.GetRequestStream())
{
stream.Write(byteArray, 0, byteArray.Length);
stream.Flush();
}
var resp = webRequest.GetResponse();
if (resp != null)
{
using (var sr = new System.IO.StreamReader(resp.GetResponseStream()))
{
var result = sr.ReadToEnd().Trim();
var iapResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<AppleIapResponse>(result);
// always getting '21002' 'java.lang.NullPointerException'
}
}
我尝试了一切:改变ContentType,JSON格式,编码......
任何提示?
答案 0 :(得分:1)
这是代码中的一个简单错误,我将收据写入POST,而不是JSON:
byte[] byteArray = Encoding.UTF8.GetBytes(json);
^^^^
墙壁因撞击它而受伤...