簡體   English   中英

使用REST API重定向到URL的問題

[英]problem in redirection to a url using rest api

我正在嘗試使用rest api重定向到外部鏈接,但未顯示所需的鏈接,而我在控制台中得到了此信息: 在此處輸入圖片說明 我正在使用angular 4 / spring boot 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);
    });
  } 

您期望使用JSON,但獲得HTML:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM