java模拟http请求的错误问题整理

时间:2021-12-10 08:42:30

java模拟http请求的时候,报错,代码,错误详情如下:

Configuration.xml

?
1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<system>
  <!--请求url-->
  <category name="url" description="指标 URL相关配置">
    <item name="volumenormUrl" value="10.150.33.154:8080/getInfo/getUser" description="临时的URL地址"></item>
  </category>
</system>

Java code

?
1
2
3
4
5
6
7
8
9
10
11
String url = Configuration.getString("url.volumenormUrl");
   try {
     log.info("=============={}",url);
     String responseString = HttpUtil.doGet(url);
     log.info("crmLoginUrl responseString {} {}", url, responseString);
     return JsonResponse.success();
   } catch (WXException e) {
     log.error("crmLogin fail... {}, e = {} ", e.getMessage(), e);
     e.printStackTrace();
     return JsonResponse.failure("fail");
   }

错误代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
java.lang.IllegalArgumentException: Illegal character in scheme name at index 0: 10.150.33.154:8080/getInfo/getUser
    at java.net.URI.create(URI.java:852)
    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
    at com.foundersc.ifc.service.base.http.HttpUtil.doGet(HttpUtil.java:30)
    at com.foundersc.ifc.volumenorm.controller.Test.getNorm(Test.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: 10.150.33.154:8080/getInfo/getUser
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.checkChars(URI.java:3021)
    at java.net.URI$Parser.checkChar(URI.java:3031)
    at java.net.URI$Parser.parse(URI.java:3047)
    at java.net.URI.<init>(URI.java:588)
    at java.net.URI.create(URI.java:850)
    ... 41 more
Disconnected from the target VM, address: '127.0.0.1:65013', transport: 'socket'
 
Process finished with exit code -1

百度了一下,发现好多没用的文章,后来上bing一搜,一下找到了根源,在configuration.xml里面的value前面一定要家http://,否则就会报错~大家放弃百度把,太坑了。

原文链接:https://blog.csdn.net/qq_21116919/article/details/67638474