将Instamojo rest api与Spring RestTemplate类一起使用

将Instamojo rest api与Spring RestTemplate类一起使用,spring,resttemplate,instamojo,Spring,Resttemplate,Instamojo,无法使用instamojo rest api在instamojo上发出付款请求获取错误请求(400),无法确定我获取400错误的原因。我正在使用SpringRESTTemplate类在instamojo上发出post请求。下面我显示了我正在使用的代码: RestTemplate restTemplate = new RestTemplate(); Map<String,Object> requestBody = new HashMap<String, Objec

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

    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);
RestTemplate RestTemplate=new RestTemplate();
Map requestBody=new HashMap();
请求主体。卖出(“金额”,“10000.00”);
requestBody.put(“目的”,“只是测试目的”);
请求主体。put(“买方名称”、“adityaPandey”);
requestBody.put(“电子邮件”,“健壮”_aditya95@xyz.com");
requestBody.put(“电话”、“+919634222331”);
put(“重定向url”,“www.imthebest.in”);
put(“webhook”,“webhook”);
requestBody.put(“允许重复付款”,false);
requestBody.put(“发送电子邮件”,false);
requestBody.put(“发送短信”,false);
HttpHeaders=新的HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
标题集(“X-Api-Key”、“me6a901b073db4715a9c540fa00af81”);
headers.set(“X-Auth-Token”,“k3c88da2cda6f89462d6002c9d24e80”);
HttpEntity请求=新的HttpEntity(requestBody.toString(),headers);
HttpEntity响应=restTemplate.exchange(“https://www.instamojo.com/api/1.1/payment-requests/,HttpMethod.POST,请求,String.class);
logger.info(“邮件响应”+响应);

我的
requestBody
数据有问题。
redirect\u url
字段值必须为
http
https
,因此仅进行此更改,我不会再收到400错误:

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

实际上,我自己解决了这个问题。执行上述代码后,我收到了400个错误。我的请求数据有问题,我没有按照instamojo标准处理请求数据,所以只需在重定向url中添加http,我就可以使用instamojo rest API。您应该将您的评论作为答案发布。谢谢bro@AshwiniChaudhary