Zhang Zhan Zhang Zhan - 3 months ago 6
iOS Question

Keep getting {"status":21002} while verifying Apple In-App Purchase receipt

Hi all I have been searching and doing troubleshooting for hours but I see getting {"status":21002} while verifying Apple In-App Purchase receipt wit AppStore in SandBox environment.

I have iOS app that sends receipt to Java Servlet, where Java Servlet send the receipt received to Apple Sandbox environment to verify.

The following is the Objective C code on iOS app side that sends the receipt to Java Servlet:

NSData *receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString *recepientValidationString = [NSString stringWithFormat:@"{\"receipt-data\": \"%@\"}", [receipt base64EncodedDataWithOptions:0]];
NSData *postData = [recepientValidationString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postStringLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:postURL];
[request setHTTPMethod:@"POST"];
[request setValue:postStringLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSHTTPURLResponse *response;
NSError *error = nil;
NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];


And the following is my Java Servlet code that sends receipt to Apple SandBox

String recepient=request.getParameter("recepient");
System.out.println("recepient is: " + recepient);
URL url = new URL(SystemConfigureFileReader.getAppStoreRecepientValidationURL());
HttpURLConnection huc = null;
huc = (HttpsURLConnection) url.openConnection();
// For post action
huc.setDoInput(true);
huc.setDoOutput(true);
huc.setRequestMethod("POST");
OutputStream os;
// Now post the request with all the parameter user inputed
os = huc.getOutputStream();
OutputStreamWriter outputStreamWriter;
String parameter=recepient;
outputStreamWriter=new OutputStreamWriter(os);
outputStreamWriter.write(parameter);
outputStreamWriter.flush();
InputStream is = huc.getInputStream();
InputStreamReader ir = new InputStreamReader(is);
BufferedReader br = new BufferedReader(ir);
String line;
StringBuffer responseStringBuffer = new StringBuffer();
String productId = null;
String statusCode = null;
//Parse the response. Please refer to Apple developer website for JSON response detail
//https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
while ((line=br.readLine())!=null) {
if (line.indexOf("\"product_id\"") > -1) {
productId = line.substring(line.indexOf(":") + 1, line.lastIndexOf("\""));
productId = productId.substring(productId.indexOf("\n")).trim();
}
if (line.indexOf("\"status\"")>-1) {
statusCode = line.substring(line.indexOf(":") + 1).trim();
if (statusCode.indexOf("}") > 0) {
statusCode = statusCode.substring(0, statusCode.indexOf("}"));
}
}
responseStringBuffer.append(line).append("\n");
}


The following is the payload I send to Apple's SandBox for verifying by Java servlet:

{"receipt-data": "<4d494954 3267594a 4b6f5a49 6876634e 41516343 6f494954 797a4343 45386343 41514578 437a414a 42675572 44674d43 47675541 4d494944 6577594a 4b6f5a49 6876634e 41516342 6f494944 62415343 41326778 67674e6b 4d416f43 41516743 41514545 41685941 4d416f43 41525143 41514545 41677741 4d417343 41514543 41514545 41774942 4144414c 41674544 41674542 42414d4d 41544577 43774942 43774942 41515144 41674541 4d417343 41513443 41514545 41774942 617a414c 41674550 41674542 42414d43 41514177 43774942 45414942 41515144 41674541 4d417343 41526b43 41514545 41774942 417a414d 4167454b 41674542 42415157 416a5172 4d413043 41513043 41514545 42514944 41574442 4d413043 41524d43 41514545 42517744 4d533477 4d413443 41516b43 41514545 42674945 55444930 4e7a4159 41674545 41674543 42424443 2b673276 36566b4c 4a617833 65537153 48724361 4d427343 41514143 41514545 45777752 55484a76 5a48566a 64476c76 626c4e68 626d5269 62336777 48414942 42514942 41515155 68466e4f 6e6b6961 69765756 65757334 417a564f 6a635242 69416b77 48674942 44414942 41515157 46685179 4d444532 4c544135 4c54417a 56444179 4f6a4d78 4f6a5135 576a4165 41674553 41674542 42425957 46444977 4d544d74 4d446774 4d444655 4d446336 4d444136 4d444261 4d434943 41514943 41514545 47677759 59323974 4c6d4676 64473973 4c6e646c 596e4268 5a325674 62323570 64473979 4d455943 41515943 41514545 506f6945 75682f6c 31747974 4f4d734e 43655762 35324b78 61414145 68705972 5a616e76 7a693072 67636257 5a534c69 686b7754 6b303243 427a497a 59525a4e 55367242 522b7935 4a43704b 32396c74 4f5a3771 4d456743 41516343 41514545 51415a36 74344346 74666247 4f454636 7868682f 2f317862 47745654 68744743 6c77746b 48534279 30476568 7953596c 612b5a6c 37707a6b 7238386a 30336968 57334f53 4669394e 48787848 6b49564f 526e6e72 76495977 6767466d 41674552 41674542 42494942 58444743 41566777 43774943 42717743 41514545 41685941 4d417343 41676174 41674542 4241494d 4144414c 41674947 73414942 41515143 46674177 43774943 42724943 41514545 41677741 4d417343 4167617a 41674542 4241494d 4144414c 41674947 74414942 41515143 44414177 43774943 42725543 41514545 41677741 4d417343 41676132 41674542 4241494d 4144414d 41674947 70514942 41515144 41674542 4d417743 41676172 41674542 42414d43 41514577 44414943 42713443 41514545 41774942 4144414d 41674947 72774942 41515144 41674541 4d417743 41676178 41674542 42414d43 41514177 47774943 42716343 41514545 45677751 4d544177 4d444177 4d44497a 4d7a5933 4d7a5579 4d544162 41674947 71514942 41515153 44424178 4d444177 4d444177 4d6a4d7a 4e6a637a 4e544978 4d423843 4167616f 41674542 42425957 46444977 4d545974 4d446b74 4d444e55 4d444936 4d7a4536 4e446c61 4d423843 41676171 41674542 42425957 46444977 4d545974 4d446b74 4d444e55 4d444936 4d7a4536 4e446c61 4d437743 4167616d 41674542 42434d4d 49574e76 62533568 62335276 62433533 5a574a77 5957646c 62573975 61585276 63693431 4d484276 61573530 63364343 446d5577 67675638 4d494945 5a4b4144 41674543 4167674f 36316548 3535344a 6a54414e 42676b71 686b6947 39773042 41515546 41444342 6c6a454c 4d416b47 41315545 42684d43 56564d78 457a4152 42674e56 42416f4d 436b4677 6347786c 49456c75 59793478 4c444171 42674e56 4241734d 49304677 6347786c 49466476 636d786b 64326c6b 5a534245 5a585a6c 62473977 5a584967 556d5673 59585270 6232357a 4d555177 51675944 56515144 44447442 63484273 5a534258 62334a73 5a486470 5a475567 52475632 5a577876 63475679 49464a6c 62474630 61573975 63794244 5a584a30 61575a70 59324630 61573975 49454631 64476876 636d6c30 65544165 46773078 4e544578 4d544d77 4d6a4531 4d446c61 46773079 4d7a4179 4d446379 4d545134 4e446461 4d49474a 4d546377 4e515944 56515144 4443354e 59574d67 51584277 49464e30 62334a6c 49474675 5a434270 56485675 5a584d67 55335276 636d5567 556d566a 5a576c77 64434254 61576475 6157356e 4d537777 4b675944 5651514c 44434e42 63484273 5a534258 62334a73 5a486470 5a475567 52475632 5a577876 63475679 49464a6c 62474630 61573975 637a4554 4d424547 41315545 4367774b 51584277 62475567 5357356a 4c6a454c 4d416b47 41315545 42684d43 56564d77 67674569 4d413047 43537147 53496233 44514542 41515541 41344942 44774177 6767454b 416f4942 4151436c 7a344839 4a614b42 57396148 37535061 4d78794f 34695041 7063516d 797a3347 6e2b784b 44565747 2f365143 3135664b 4f565274 66582b79 56426964 78437853 6359356b 65344c4f 6962704a 31676a6c 74496878 7a7a3962 52693747 78423234 41366c59 6f67512b 49586a56 32376651 6a684b4e 67307862 4b6d6733 6b384c79 76523745 3071454d 536c6853 71784c6a 37643066 6d425751 4e533343 7a424c4b 6a556942 39316834 5647766f 6a444532 48306f47 44456455 387a6551 754c4b53 69583166 7049564b 34634363 344c716b 75344b58 592f5172 6b384839 506d2f4b 77665538 71593953 4773416c 436e594f 3376365a 2f762f43 612f5662 5871787a 55556b49 566f6e4d 5135444d 6a6f4543 304b4358 746c7978 6f576c70 68354151 6143596d 4f626764 45484f77 436c3346 63394466 646a7659 4c646d49 48755073 42382f69 6a744454 2b695a56 67652f69 41306b6a 41674d42 4141476a 67674858 4d494942 307a412f 42676772 42674546 42516342 4151517a 4d444577 4c775949 4b775942 42515548 4d414747 49326830 64484136 4c793976 59334e77 4c6d4677 6347786c 4c6d4e76 62533976 59334e77 4d444d74 6433646b 636a4130 4d423047 41315564 44675157 42425352 704a7a38 78486133 6e36434b 39453331 6a7a5a64 37537345 6854414d 42674e56 48524d42 41663845 416a4141 4d423847 41315564 49775159 4d426141 4649676e 46776d70 74686867 692b7a72 75765a48 57635653 564b4f33 4d494942 48675944 56523067 42494942 46544343 41524577 6767454e 42676f71 686b6947 39324e6b 42515942 4d49482b 4d494844 42676772 42674546 42516343 416a4342 74677942 73314a6c 62476c68 626d4e6c 49473975 4948526f 61584d67 59325679 64476c6d 61574e68 64475567 596e6b67 59573535 49484268 636e5235 4947467a 63335674 5a584d67 59574e6a 5a584230 5957356a 5a534276 5a694230 61475567 6447686c 62694268 63484273 61574e68 596d786c 49484e30 5957356b 59584a6b 4948526c 636d317a 49474675 5a43426a 6232356b 61585270 6232357a 4947396d 4948567a 5a537767 59325679 64476c6d 61574e68 64475567 63473973 61574e35 49474675 5a43426a 5a584a30 61575a70 59324630 61573975 49484279 59574e30 61574e6c 49484e30 5958526c 62575675 64484d75 4d445947 43437347 41515546 42774942 4669706f 64485277 4f693876 64336433 4c6d4677 6347786c 4c6d4e76 6253396a 5a584a30 61575a70 59324630 5a574631 64476876 636d6c30 65533877 44675944 56523050 4151482f 42415144 41676541 4d424147 43697147 53496233 59325147 43774545 41675541 4d413047 43537147 53496233 44514542 42515541 41344942 4151414e 70687654 4c6a336a 57797348 626b4b57 624e506f 6a454d77 676c2f67 584e474e 76723050 76527238 4a5a4c62 6a495844 67466e66 342b4c58 4c675555 72413362 74726a2b 2f445575 664d7574 4632754f 66782f6b 64376d78 5a355730 4531366d 47595a32 2b466f67 6c65646a 6a41397a 2f4f6a74 78682b75 6d66686c 53467967 34436736 77424133 4c626d67 42446b66 63376e49 42663379 336e3861 4b697075 4b774838 6f434263 32657439 4a36597a 2b505759 344c3545 3237464d 5a2f7875 436b2f4a 3467616f 3070667a 70343572 55614a61 6848566c 30525945 59755042 582f5549 7163396f 325a4941 7963474d 732f694e 41475336 57474441 664b2b50 64637070 75567371 3168316f 62706843 3955796e 4e786d62 7a447363 65686c44 38364e74 76306867 42677732 6b697673 33686931 45646f74 4939434f 2f4b4270 6e426362 6e6f4237 4f556446 4d474576 78784f6f 4d494945 496a4343 41777167 41774942 41674949 41643638 78446c74 6f424177 4451594a 4b6f5a49 6876634e 41514546 42514177 596a454c 4d416b47 41315545 42684d43 56564d78 457a4152 42674e56 42416f54 436b4677 6347786c 49456c75 59793478 4a6a416b 42674e56 42417354 48554677 6347786c 49454e6c 636e5270 5a6d6c6a 59585270 62323467 51585630 61473979 61585235 4d525977 46415944 56515144 45773142 63484273 5a534253 62323930 49454e42 4d423458 4454457a 4d444977 4e7a4978 4e446730 4e316f58 4454497a 4d444977 4e7a4978 4e446730 4e316f77 675a5978 437a414a 42674e56 42415954 416c5654 4d524d77 45515944 5651514b 44417042 63484273 5a53424a 626d4d75 4d537777 4b675944 5651514c 44434e42 63484273 5a534258 62334a73 5a486470 5a475567 52475632 5a577876 63475679 49464a6c 62474630 61573975 637a4645 4d454947 41315545 41777737 51584277 62475567 56323979 62475233 6157526c 4945526c 646d5673 6233426c 63694253 5a577868 64476c76 626e4d67 51325679 64476c6d 61574e68 64476c76 62694242 6458526f 62334a70 64486b77 67674569 4d413047 43537147 53496233 44514542 41515541 41344942 44774177 6767454b 416f4942 4151444b 4f46536d 79316171 79435135 534f6d4d 37757866 7548386d 6b627730 5533724f 66474f41 5958646b 58715548 49375935 2f6c4174 46565a59 6343312b 78473742 536f552b 4c2f4465 68427168 56386d76 65786a2f 61766f56 456b6b56 43426d73 71747371 4d753257 59326853 4654324d 6975792f 61786956 34414f73 41583258 4257664f 446f5756 4e327274 43626175 5a383152 5a4a2f47 584e4738 5632356e 4e594232 4e715348 67573434 6a396772 46553537 4a646861 76303644 77593353 6b395561 63625667 6e4a307a 546c5835 456c674d 68726757 4463486c 6430574e 55456936 4b79336b 6c495868 364d5364 786d696c 734b5038 5a333577 75674a5a 53336443 6b546d35 39633368 544f2f41 4f30694d 70755568 58663171 6172756e 466a5667 30756174 38305970 79656a44 692b6c35 77477068 5a785779 3850336c 614c7869 58323750 6d643376 4732502b 6b6d5772 41674d42 4141476a 67615977 67614d77 48515944 5652304f 42425945 4649676e 46776d70 74686867 692b7a72 75765a48 57635653 564b4f33 4d413847 41315564 45774542 2f775146 4d414d42 41663877 48775944 5652306a 42426777 466f4155 4b394270 52355232 43663730 61343075 514b6233 5230312f 43463477 4c675944 56523066 42436377 4a54416a 6f434767 48345964 61485230 63446f76 4c324e79 62433568 63484273 5a53356a 62323076 636d3976 6443356a 636d7777 44675944 56523050 4151482f 42415144 41674747 4d424147 43697147 53496233 59325147 41674545 41675541 4d413047 43537147 53496233 44514542 42515541 41344942 41514250 7a2b395a 76697a31 736d7776 6a2b3454 687a4c6f 4254576f 626f7439 79576b4d 75646b58 76486373 31476669 2f5a7074 4f6c6c63 33344d42 76624b75 4b6d4679 73612f4e 77305577 6a364f44 44633464 52375478 6b34716a 644a756b 77356879 687a732b 7230554c 6b6c5335 4d727551 47464e72 436b3451 74746b64 55477768 6741714a 546c654d 61317338 50616239 3376634e 4978304c 53696148 50377152 6b6b796b 4752495a 62566631 656c6948 6532694b 3549614d 53757669 53525371 70643156 414b6d75 75307377 72754767 73627770 674f594a 642b572b 4e4b4942 796e2f63 3467726d 4f376937 374c7069 6c664d46 59304743 7a513837 48557956 704e7572 2b636d56 36552f6b 5465636d 6d594870 76506d30 4b644942 656d6268 4c6f7a32 49597246 2b486a68 6761362f 30354364 7161337a 722f3034 47705a6e 4d427852 70567a73 63597143 74477750 44425566 4d494945 757a4343 41364f67 41774942 41674942 416a414e 42676b71 686b6947 39773042 41515546 41444269 4d517377 43515944 56515147 45774a56 557a4554 4d424547 41315545 43684d4b 51584277 62475567 5357356a 4c6a456d 4d435147 41315545 43784d64 51584277 62475567 51325679 64476c6d 61574e68 64476c76 62694242 6458526f 62334a70 64486b78 466a4155 42674e56 42414d54 44554677 6347786c 49464a76 62335167 51304577 4868634e 4d445977 4e444931 4d6a4530 4d444d32 5768634e 4d7a5577 4d6a4135 4d6a4530 4d444d32 576a4269 4d517377 43515944 56515147 45774a56 557a4554 4d424547 41315545 43684d4b 51584277 62475567 5357356a 4c6a456d 4d435147 41315545 43784d64 51584277 62475567 51325679 64476c6d 61574e68 64476c76 62694242 6458526f 62334a70 64486b78 466a4155 42674e56 42414d54 44554677 6347786c 49464a76 62335167 51304577 67674569 4d413047 43537147 53496233 44514542 41515541 41344942 44774177 6767454b 416f4942 4151446b 6b616b4a 48354862 486b6451 36775874 586e6d45 4c657332 6f6c644d 5665794c 47596e65 2b557473 39516572 496a4143 3642672b 2b46414a 30333942 714a6a35 3063706d 6e435272 4564436a 752b5162 4b734d66 6c5a3536 444b5248 69317655 466a637a 79385150 54633455 6164484a 47584c31 58513756 66312b62 38695544 756c5750 5456304e 38575131 4978564c 46566b64 73355433 39707965 7a314336 77566851 5a343849 74434433 79367773 49473977 746a3842 4d497933 51383850 6e54337a 4b306b6f 47736a2b 7a725735 44746c65 484e624c 50625536 72665150 44674353 43374568 46693530 3154774e 32324957 71364e78 6b6b6454 56634776 4c30477a 2b50766a 634d336d 6f307846 6668394d 61314357 51596e45 6447494c 45494e42 687a4f4b 67624577 574f7861 42444b4d 614c4f50 4864356c 632f396e 586d5738 53646832 6e7a4d55 5a614633 6c4d6b74 41674d42 4141476a 67674636 4d494942 646a414f 42674e56 48513842 41663845 42414d43 41515977 44775944 56523054 4151482f 42415577 41774542 2f7a4164 42674e56 48513445 46675155 4b394270 52355232 43663730 61343075 514b6233 5230312f 43463477 48775944 5652306a 42426777 466f4155 4b394270 52355232 43663730 61343075 514b6233 5230312f 43463477 67674552 42674e56 48534145 67674549 4d494942 42444343 41514147 43537147 53496233 59325146 41544342 386a4171 42676772 42674546 42516343 41525965 61485230 63484d36 4c793933 64336375 59584277 62475575 59323974 4c324677 6347786c 59324576 4d494844 42676772 42674546 42516343 416a4342 74687142 73314a6c 62476c68 626d4e6c 49473975 4948526f 61584d67 59325679 64476c6d 61574e68 64475567 596e6b67 59573535 49484268 636e5235 4947467a 63335674 5a584d67 59574e6a 5a584230 5957356a 5a534276 5a694230 61475567 6447686c 62694268 63484273 61574e68 596d786c 49484e30 5957356b 59584a6b 4948526c 636d317a 49474675 5a43426a 6232356b 61585270 6232357a 4947396d 4948567a 5a537767 59325679 64476c6d 61574e68 64475567 63473973 61574e35 49474675 5a43426a 5a584a30 61575a70 59324630 61573975 49484279 59574e30 61574e6c 49484e30 5958526c 62575675 64484d75 4d413047 43537147 53496233 44514542 42515541 41344942 41514263 4e706c4d 4c586933 37597962 33504e33 6d2f4a32 306e6377 54384566 68594f46 47356b39 527a6679 715a7441 6a697a55 735a4153 324c3730 63357675 306d5150 79336c50 4e4e6969 50766c34 2f327649 422b7839 4f594f4c 55794454 4f4d5378 76357050 436d762f 4b2f785a 7077554a 66426441 56684565 644e4f33 69794d37 52365056 62795469 36394733 634e3850 5265456e 79764674 654f336e 74526358 714e782b 496a584b 4a64585a 44395a72 314b496b 49784833 6f617950 63344667 78687462 43532b53 73766845 53504267 4f4a3456 3954306d 5a79434b 4d327233 44594c50 3375756a 4c2f6c54 616c746b 77474d7a 642f6336 42797857 36396f50 49513761 756e4d5a 5437585a 4e6e2f42 6831585a 70356d35 4d6b4c37 324e5678 6e6e3668 55726362 765a4e43 4a424971 78773864 746b3263 586d5049 53344158 554b714b 3164726b 2f4e414a 427a6577 64585568 4d594942 797a4343 41636343 41514577 67614d77 675a5978 437a414a 42674e56 42415954 416c5654 4d524d77 45515944 5651514b 44417042 63484273 5a53424a 626d4d75 4d537777 4b675944 5651514c 44434e42 63484273 5a534258 62334a73 5a486470 5a475567 52475632 5a577876 63475679 49464a6c 62474630 61573975 637a4645 4d454947 41315545 41777737 51584277 62475567 56323979 62475233 6157526c 4945526c 646d5673 6233426c 63694253 5a577868 64476c76 626e4d67 51325679 64476c6d 61574e68 64476c76 62694242 6458526f 62334a70 64486b43 43413772 5634666e 6e676d4e 4d416b47 4253734f 41774961 42514177 4451594a 4b6f5a49 6876634e 41514542 42514145 67674541 4178582b 35694e65 49386261 4b545977 44345668 2b51354e 49627738 68684f34 74476133 6b737234 30414d49 6c525479 4c504f34 42762b58 556e6232 6c552f66 5967655a 6f633953 70524c51 6f4b4e4e 6a445539 3542444e 3034484a 746f3375 56565730 6b36485a 68364351 70385950 464f4751 75613357 75314f48 6f763170 7a486477 5375696f 71767764 70417263 6479594a 497a2b66 58503242 6b4a5764 626c4d6a 6e684968 7a726d52 792b2f68 51516b58 4a65432b 4b376a53 2b304e52 516d6345 792b2f4f 352f4174 562f6941 55727a65 742f7566 3550516c 4c4f6467 5a785772 3562634c 46437863 6c414d63 37417962 71774548 39713273 4c735749 64303673 537a6949 6e53767a 704a5948 61393631 39517376 2b326837 645a6446 5976494b 4d4e5349 6f70704b 48646352 6f4e5155 39524b76 43352f5a 66553049 324a6337 39624f56 37714841 78535672 46516762 57673d3d>"}


Please help.

Thank you.

=========================================

Update:
After changing from base64EncodedDataWithOptions to base64EncodedStringWithOptions, the payload is now

{"receipt-data": "MIIT3gYJKoZIhvcNAQcCoIITzzCCE8sCAQExCzAJBgUrDgMCGgUAMIIDfwYJKoZIhvcNAQcBoIIDcASCA2wxggNoMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATEwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBazALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDAWDBMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI0NzAYAgEEAgECBBCfHYNk3By9WFs9LK7zyxOsMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwHAIBBQIBAQQU8UOAliZHFFCQyalZejQBTuLrMREwHgIBDAIBAQQWFhQyMDE2LTA5LTAzVDExOjEyOjIwWjAeAgESAgEBBBYWFDIwMTMtMDgtMDFUMDc6MDA6MDBaMCICAQICAQEEGgwYY29tLmFvdG9sLndlYnBhZ2Vtb25pdG9yMEECAQcCAQEEOXcEWFoG3R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FYRHnTTt4sjO0ej1W8k4uvRt3DfD0XhJ8rxbXjt57UXF6jcfiI1yiXV2Q/Wa9SiJCMR96Gsj3OBYMYbWwkvkrL4REjwYDieFfU9JmcgijNq9w2Cz97roy/5U2pbZMBjM3f3OgcsVuvaDyEO2rpzGU 12TZ/wYdV2aeZuTJC 9jVcZ5 oVK3G72TQiQSKscPHbZNnF5jyEuAF1CqitXa5PzQCQc3sHV1ITGCAcswggHHAgEBMIGjMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECgwKQXBwbGUgSW5jLjEsMCoGA1UECwwjQXBwbGUgV29ybGR3aWRlIERldmVsb3BlciBSZWxhdGlvbnMxRDBCBgNVBAMMO0FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zIENlcnRpZmljYXRpb24gQXV0aG9yaXR5AggO61eH554JjTAJBgUrDgMCGgUAMA0GCSqGSIb3DQEBAQUABIIBAE/gN4LG/0rl58//XPx8XU8mfQRiboL PWkcUp0Qs8EOfmINm cRj11lpnDs9mvBgOSurzFt0Ry1PSIQXxS2OSZeHlPl3v40p1Iq38KrURO4BjNo5ghneFf3oaG9z6b1ldWL09i ezvE//Mq4KYLy/lMXQbQRpSwHm1IRgSx5X8oGguEB/PJsWMgZCRoneXp iTjVjghrr0hDH5Ghjs iHBzTJz05gBFCPVm1rfMgS8BpF5fA9cs7jyxsrJ /sbZLPgQqEzZ/p8kthEC5J8KJTNAdn9 KCjcQ7MzysK4D/K0kWKBpNAk2B8cXzD18pnoUyWI05UrMBBsKmiI6QOrQsA="}


However, I get error

{"status":21002, "exception":"java.lang.IllegalArgumentException"}

Answer

Two problems exist in your code:

  1. You need to use base64EncodedStringWithOptions instead of base64EncodedDataWithOptions. The former as you can see returns a data hash, not a base64 encoded string which Apple requires.
  2. Since you're posting JSON to Apple you need to set the Content-type to application/json instead of application/x-www-form-urlencoded;charset=UTF-8.
Comments