请求返回404状态

时间:2021-01-28 20:21:19

标签: java http

我正在尝试在 Java 中创建一个端点。我正在添加授权作为标题,这是正确的 [经测试和验证]。功能如下:

private static HttpResponseResult response(HttpUriRequest request) {
        request.addHeader("content-type", "application/json");
        request.addHeader("Authorization", "Basic " + authHeader);
        try {
            HttpResponse response = httpClient.execute(request);
            LOGGER.info("status code is: {}", response.getStatusLine().getStatusCode()); 
// here when I am printing I am getting 404.
            HttpEntity entity = response.getEntity();
            String responseBody = null;
            if (entity != null) {
                responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); 
// response body here is showing: Unable to extract parameter from http request: javax.ws.rs.PathParam("templateId")                }
                int statusCode = response.getStatusLine().getStatusCode();
            } catch (Exception ex) {
    LOGGER.error("{}, {}", ex.getMessage(), request.getURI());
                return internalErrorResult(ex);
            }
        }

我不确定为什么会收到 404。有人可以帮忙吗?

端点如下:

@GET
  @Path("something/{p1}/{p2}")
  @Produces(MediaType.APPLICATION_JSON)
  @Timed(name = "get-requests-timed")
  @Metered(name = "get-requests-metered")
  public Response func(
          @PathParam("p1") String p1,
          @PathParam("p2") String p2) {
    Response response = functionName(p2);
    return response;
  }

不确定网址中的 ("templateId") 在哪里。

0 个答案:

没有答案