首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Instamojo rest api与Spring RestTemplate类结合使用

将Instamojo rest api与Spring RestTemplate类结合使用
EN

Stack Overflow用户
提问于 2017-03-28 18:04:09
回答 1查看 131关注 0票数 2

无法通过使用instamojo rest api获取错误请求在instamojo上进行付款请求( 400 ),无法确定我获取400错误的原因。我正在使用spring RestTemplate类在instamojo上发出post请求。下面显示了我正在使用的代码:

代码语言:javascript
复制
    RestTemplate restTemplate = new RestTemplate();
    Map<String,Object> requestBody = new HashMap<String, Object>();
    requestBody.put("amount", "10000.00");
    requestBody.put("purpose", "just_testing_purpose");
    requestBody.put("buyer_name", "adityaPandey");
    requestBody.put("email", "robust_aditya95@xyz.com");
    requestBody.put("phone", "+919634222331");
    requestBody.put("redirect_url", "www.imthebest.in");
    requestBody.put("webhook", "");
    requestBody.put("allow_repeated_payments", false);
    requestBody.put("send_email", false);
    requestBody.put("send_sms", false);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set("X-Api-Key", "me6a901b073db4715a9c540fa00af81");
    headers.set("X-Auth-Token", "k3c88da2cda6f89462d6002c9d24e80");

    HttpEntity<String> request = new HttpEntity<String>(requestBody.toString(), headers);

    HttpEntity<String> response = restTemplate.exchange("https://www.instamojo.com/api/1.1/payment-requests/", HttpMethod.POST, request, String.class);
    logger.info("MailResponse "+ response);
EN

回答 1

Stack Overflow用户

发布于 2017-04-11 17:33:30

我的requestBody数据有问题。redirect_url字段的值必须是httphttps,所以只需进行此更改,我就不会再收到400错误:

代码语言:javascript
复制
requestBody.put("redirect_url", "http://www.imthebest.in")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43066569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档