【问题标题】:problem in redirection to a url using rest api使用rest api重定向到url的问题
【发布时间】:2019-04-17 12:10:27
【问题描述】:

我正在尝试使用 rest api 重定向到外部链接,但没有显示所需的链接,我在控制台得到了这个: 我正在使用角度 4 / 弹簧靴 2 ** 当我使用邮递员发送请求时,它会返回链接的代码 html:

我的弹簧代码:

@GetMapping("/create")
static public RedirectView createPayment(HttpServletRequest req, HttpServletResponse res)
        throws Exception {

    TransactionRequest request = new TransactionRequest();

    request.setOrderId("1242").setCurrency("MAD").setAmount(1500);
    request.setShippingType(ShippingType.VIRTUAL);
    request.setPaymentMode(PaymentMode.SINGLE);
    request.setPaymentType(PaymentType.CREDIT_CARD); 
    request.setCtrlRedirectURL("http://capmission.ma");
    request.setCustomerIP("105.159.248.185");

    try {
        request.validate();
    } catch (BadRequestException e) {
        throw new Exception("Ooops, an error occurred validating the payment request: " + e.getMessage());
    }
    Connect2payClient c2p = new Connect2payClient("https://paiement.payzone.ma", "104747", "vbK7@pQ3G@W9X2k2");
    TransactionResponse response = null;
    try {
        response = c2p.prepareTransaction(request);
    } catch (Exception e) {
        throw new Exception("Ooops, an error occurred preparing the payment: " + e.getMessage());
    }
    if (response != null && ResultCode.SUCCESS.equals(response.getCode())) {
        response.setCustomerToken(response.getCustomerToken());
        String redirectURL = response.getCustomerRedirectURL();
        System.out.println(redirectURL);
        if (redirectURL != null) {
            return new RedirectView("https://www.google.com");
        }
    } else {
        System.out.println(response.getCode());
    }
    return null;
}

我的角码:

//service : 
    public testPaiementEnLigne2(){
        return 
         this.http.get(this.baseUrl+"payzone/create").map(data=>data.json());
    }

执行重定向的函数:

payer2(){
    this.paiementService.testPaiementEnLigne2().subscribe(
      data=>{
        console.log(data);
      },
      err=>{
        console.log(err);
    });
  } 

【问题讨论】:

    标签: angular spring spring-boot


    【解决方案1】:

    您期望的是 JSON,但您得到的是 HTML:

    //service : 
        public testPaiementEnLigne2(){
            return 
             this.http.get(this.baseUrl+"payzone/create").map(data=>data.text());
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 2020-09-12
      • 2021-01-09
      相关资源
      最近更新 更多