我正在尝试使用 Apple 的沙盒服务器验证不可更新的订阅,但不断返回verify response: { "status":21002 }
,这意味着请求格式不正确。这是我正在使用的相关代码:
NSString *receiptString = [[NSString alloc] initWithData:transactionReceipt
encoding:NSUTF8StringEncoding];
NSString *encodedString = [receiptString base64Encoding];
NSString *jsonString = [NSString stringWithFormat:@"{ 'receipt-data' : '%@' }", encodedString];
NSURL *verificationURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:verificationURL];
[request appendPostData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
NSLog(@"verify response: %@", responseString);
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"verify error: %@", [error description]);
}];
[request startAsynchronous];
显然问题是我通过 ASIHTTPRequest 库向 Apple 发送数据的方式。对此的任何见解表示赞赏。提前致谢!