我是Spring Boot和REST API的初学者。我正在尝试集成用于创建付款请求的付款网关,并且为此使用Instamojo付款网关。我收到200个成功代码的响应中为NULL。 postForObject
,postForEntity
或某些人使用交换方式的主要区别是什么?看来postForEntity
和交换方法用于获取reponseEntity
的退货,我什么时候应该使用postForObject
,postForEntity
或交换方法?谁能告诉我我在做什么错?
@PostMapping(value="/paymentcreate")
public void createOrderCashFree(@RequestBody CreateOrder createorder) {
CreateOrder corder = new CreateOrder();
corder.setAmount(createorder.getAmount());
corder.setBuyer_name(createorder.getBuyer_name());
corder.setEmail(createorder.getEmail());
corder.setPurpose(createorder.getPurpose());
corder.setPhone(createorder.getPhone());
corder.setRedirect_url("https://www.google.com/"); // just for test
corder.setWebhook("");
corder.setAllow_repeated_payments(false);
corder.setSend_email(false);
corder.setSend_sms(false);
corder.setExpire_at(new Date());
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
header.set("X-Api-Key", "test-api-key"); // actual key is provided
header.set("X-Auth-Token","test-auth-token"); // actual token is provided
HttpEntity<CreateOrder> entity = new HttpEntity<CreateOrder>(corder, header);
System.out.println(entity.getBody());
CreateOrder response =resttemplate.postForObject("https://test.instamojo.com/api/1.1/payment-requests/", entity, CreateOrder.class);
System.out.println(response); // this return null
}
预期结果是对某些字段的响应,但实际结果是 成功代码为200,但体内为NULL。