Spring RestTemplate收到“ 401未经授权”

时间:2020-07-18 23:50:58

标签: java spring-boot resttemplate

我有一个rest get API,当我调用消耗的API获取实体以及在其中使用API​​时,我的另一个应用程序正在消耗该API

路径为[/ localdeal]的上下文中servlet [dispatcherServlet]的

Servlet.service()引发异常[请求处理失败;嵌套的异常是org.springframework.web.client.HttpClientErrorException $ Unauthorized:401 Unauthorized:[

401 Unauthorized

您需要有效的用户名和密码才能访问此内容。

]]与根本原因

org.springframework.web.client.HttpClientErrorException $未经授权:401未经授权:[

401未经授权

您需要有效的用户名和密码才能访问此内容。

它对多个匹配都很有用,任何建议为什么

  @PostMapping(value = "/psRequestController")
    public ResponseEntity<Map<String, Object>> getAllLocationByUser(
            @RequestBody UserLookupInformation userLookupInformation) {
        Map<String, Object> result = new HashMap<String, Object>();
        ResponseEntity<FinancialTx[]> response =
                restTemplate.getForEntity(
                        userFxRequestUrl + userLookupInformation.getUserEmail(),
                        FinancialTx[].class);
        List<VendorDto> vendors =
                vendorService.getAllLocationByLocationAndUserValidation(
                        userLookupInformation.getLatitude(), userLookupInformation.getLongitude());
        FinancialTx[] financialTx = response.getBody();
        if (financialTx.length >= 1 && financialTx.length != 0 && vendors.size() > 0) {
            return new ResponseEntity(vendors, HttpStatus.OK);
        } else if (vendors.size() <= 0 && financialTx.length >= 1) {
            result.put(
                    "message",
                    "Oops! Looks like there is no deal available from any nearby vendor.");
            return ResponseEntity.status(NO_LOCAL_DEAL_FOUND).body(result);
        }
        result.put(
                "message",
                "Sorry! You need to have an active parking session in the last "
                        + psValidationDays
                        + " days to access deals from nearby vendors.");
        return ResponseEntity.status(NO_PARKING_SESSION_FOUND).body(result);
    
    }

0 个答案:

没有答案