我正在使用Quarkus Rest Client对外部 API 服务执行 GET 请求。但是,此服务不会直接返回我需要接收的资源 (XML),但它会重定向到另一个返回资源的 API 服务。
当我尝试导航到向 API 服务询问资源的路径时(即 localhost:8080/hello),我被重定向到包含资源的页面,而不是接收和处理它。
在请求之后放置断点,表明请求之后的代码部分永远不会到达。这是端点的代码:
@Path("/hello")
public class GreetingResource {
@Inject
@RestClient
MyService myService;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
myService.performGet();
return "you are here"; // breakpoint here, it is never reached
}
}
这是 MyService 的代码:
@Path("/..")
@RegisterRestClient(configKey="key")
public interface MyService {
@GET
@Path("/..")
@Produces(MediaType.TEXT_XML)
String performGet(@QueryParam("c") String c, @QueryParam("d") String d);
}
我试图添加配置key/mp-rest/followRedirects=true
,但我仍然遇到同样的问题。此外,使用没有重定向的路径,一切正常。
使用本机 HttpURLConnection 也可以正常工作,但是,由于我使用的是 Quarkus,我想改用它的功能。