繁体   English   中英

Spring Boot中的嵌套请求

[英]Nested Requests in Spring Boot

使用Spring Boot创建Rest服务时,将为特定路径执行@GetMapping。 从那时起,我尝试发出一个正常的HTTP请求,并且得到各种各样的异常: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/message/TokenParser org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/message/TokenParser或错误: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Target host is null org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Target host is nullorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Target host is null ,这取决于我如何解决。 我原则上了解该问题,但没有找到解决方案。 我附上示例代码:

@GetMapping看起来像这样:

  @GetMapping("/requesttest")
  public String TestRequest(@RequestParam("requestlink") String requestlink ) throws Exception {
    String requesttext = RHRequest.getHRequest(requestlink);
    return requesttext;
  }

请求类:

public class RHRequest {
  public static String getHRequest(String urlRequest) throws Exception {

    HttpGet httpRequest = new HttpGet(urlRequest);
    HttpClient httpClientRequest = new DefaultHttpClient();
    HttpContext localContextRequest = new BasicHttpContext();
    ResponseHandler<String> handlerRequest = new BasicResponseHandler();
    String responseBodyRequest = null;
    HttpResponse responseHRequest = httpClientRequest.execute(httpRequest, localContextRequest);
    responseBodyRequest = handlerRequest.handleResponse(responseHRequest);
    return responseBodyRequest.toString();
  }
}

问题已解决。

显然,SSLContexts类已与其他修改一起重定位到了httpclient 4.4中的另一个程序包。 我将httpcore版本4.4和httpclient升级到4.5,问题已修复。

另一个问题是我用于请求的链接应该已经编码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM