【问题标题】:using Instamojo rest api with Spring RestTemplate class使用带有 Spring RestTemplate 类的 Instamojo rest api
【发布时间】:2017-03-28 10:04:09
【问题描述】:

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

    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);

【问题讨论】:

  • 我自己解决这个问题实际上我通过执行上面的代码得到 400 错误
  • 我的请求数据有问题,我没有遵循 instamojo 请求数据标准,所以只需在重定向 url 中添加 http 我就可以 instamojo rest api
  • 你应该发表你的评论作为答案。
  • 谢谢兄弟@AshwiniChaudhary

标签: spring resttemplate instamojo


【解决方案1】:

我的requestBody 数据有问题。 redirect_url 字段值必须与 httphttps 一起使用,因此只需进行此更改,我就不会再收到 400 错误:

requestBody.put("redirect_url", "http://www.imthebest.in")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-11
    • 2016-04-11
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 2018-04-18
    • 2017-11-06
    • 1970-01-01
    相关资源
    最近更新 更多