gpt4 book ai didi

micronaut - HttpClientResponseException : Empty body

转载 作者:行者123 更新时间:2023-12-04 15:42:18 25 4
gpt4 key购买 nike

我对使用 declarative http client 感到困惑.

我正在尝试创建一个 declarative http client .但是我收到了这个错误。

15:34:16.455 [pool-1-thread-1] ERROR i.m.r.intercept.RecoveryInterceptor - Type [micronaut.http.client.repository.ItunesClient$Intercepted] executed with error: Empty body
io.micronaut.http.client.exceptions.HttpClientResponseException: Empty body
at io.micronaut.http.client.BlockingHttpClient.lambda$retrieve$0(BlockingHttpClient.java:140)
at java.util.Optional.orElseThrow(Optional.java:290)
at io.micronaut.http.client.BlockingHttpClient.retrieve(BlockingHttpClient.java:140)
at io.micronaut.http.client.interceptor.HttpClientIntroductionAdvice.intercept(HttpClientIntroductionAdvice.java:535)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:40)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:146)
at io.micronaut.retry.intercept.RecoveryInterceptor.intercept(RecoveryInterceptor.java:73)
at io.micronaut.aop.MethodInterceptor.intercept(MethodInterceptor.java:40)
at io.micronaut.aop.chain.InterceptorChain.proceed(InterceptorChain.java:146)
at micronaut.http.client.repository.ItunesClient$Intercepted.search(Unknown Source)
at micronaut.http.client.controller.MusicController.search(MusicController.java:37)
at micronaut.http.client.controller.$MusicControllerDefinition$$exec1.invokeInternal(Unknown Source)
at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:144)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2694)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:295)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
at io.micronaut.http.server.netty.RoutingInBoundHandler.lambda$buildResultEmitter$17(RoutingInBoundHandler.java:1358)

这是我的代码。 https://github.com/akyong/micronaut-http-client/blob/master/src/main/java/micronaut/http/client/controller/MusicController.java#L25-L37

如果我改变 List<Album> 它会起作用至 String像这样。

public String search(String searchTerm, @Nullable @QueryValue String maxResults) {
log.info("searchTerm : {}",searchTerm);
log.info("maxResults : {}",maxResults);
final int limit;
if(StringUtils.isDigits(maxResults)) {
limit = Math.min(25, Integer.parseInt(maxResults));
} else {
limit = 25;
}

String result = itunesClient.search(searchTerm, limit);
return result;
}

iTunes 客户端

@Get("/search?limit={maxResults}&media=music&entity=album&term={term}")
String search(String term, int maxResults);//From SearchResults to String

最佳答案

src/main/resources/application.yml 中设置这个...

micronaut:
codec:
json:
additionalTypes:
- text/javascript

这是必需的,因为从 Apple 返回的响应内容类型。参见 https://github.com/jeffbrown/music-search/blob/30cda075cb8e9450ff920349ca5d5e986db32fbf/music-service/src/main/resources/application.yml#L13-L16举个例子。

关于micronaut - HttpClientResponseException : Empty body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57426422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com