我正在尝试使用 rest 模板从 apple inapp purchase api 进行验证,但失败了。 (在 postman 中工作正常)。 postman 收藏:collection postman
如何使用 rest 模板将其存档?是否不允许使用 base64 编码的数据?
` HttpHeaders httpHeaders = new HttpHeaders(); //httpHeaders.setContentType(MediaType.APPLICATION_JSON); //httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add(Constant.PURCHASE.RECEIPT_DATA, purchase.getReceiptData());
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, httpHeaders);
ResponseEntity<String> postResponse = restTemplate.postForEntity(iosPurchaseService, request, String.class);`
最佳答案
您可以使用具有以下属性的对象来发送您需要提供的值作为 API 调用的输入,而不是在 MultiValueMap 中提供它。
public class SomeObject implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("receipt-data")
private String receiptdata;
}
然后按如下方式将此对象绑定(bind)到您的 Controller 中。
public void apiCall(@RequestBody SomeObject someObject) {
//Method 1
ResponseEntity<String> response1 = restTemplate.postForEntity("https://sandbox.itunes.apple.com/verifyReceipt", someObject,
String.class);
// or Method 2
ResponseEntity<String> response2 = restTemplate.exchange("https://sandbox.itunes.apple.com/verifyReceipt", HttpMethod.POST, new HttpEntity<>(someObject, null),
String.class);
}
关于ios - Rest模板发送苹果验证数据失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50569357/