gpt4 book ai didi

ios - Rest模板发送苹果验证数据失败

转载 作者:行者123 更新时间:2023-11-28 23:57:57 27 4
gpt4 key购买 nike

我正在尝试使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com