java.net.URISyntaxException:索引为75的路径中的非法字符
我试图通过Apache REST客户端从Java发送GET请求,并遇到此问题。
java.net.URISyntaxException:位于索引75处的路径中的非法字符:http://resolver.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Shared Documents / test')/ files at java.net.URI $ Parser.fail (URI.java:2848)at java.net.URI $ Parser.checkChars(URI.java:3021)位于java.net.URI $ Parser.parseHierarchical(URI.java:3105)位于java.net.URI $ Parser。在org.apache.http.client.utils.URIBuilder的java.net.URI。(URI.java:588)处解析(URI.java:3053)。(URIBuilder.java:82)at com.mstack.samples.sharepoint .SharePointApp.getAllFiles(SharepointApp.java:61)at com.mstack.samples.sharepoint.SharepointApp.main(SharepointApp.java:45)
代码片段: -
httpClient = HttpClientBuilder.create().build();
uriBuilder = new URIBuilder(requestUrl);
System.out.println(uriBuilder);
httpGet = new HttpGet(uriBuilder.build());
httpGet.addHeader(AUTHORIZATION, "Bearer " + TOKEN);
httpGet.addHeader("accept", "application/json; odata=verbose");
response = httpClient.execute(httpGet);
其中requestUrl是http://torrento.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Shared Documents/test')/files
我知道Shared和Documents之间的空间是问题。 试图编码它。 但那也行不通。 请帮忙
我通过简单添加requestUrl.replaceAll(" ", "%20");
获得了解决方案requestUrl.replaceAll(" ", "%20");
但是在其他特殊字符的情况下,这是行不通的。 所以我们必须在发送请求之前编码url。
干杯:)
链接地址: http://www.djcxy.com/p/70205.html上一篇: java.net.URISyntaxException: Illegal character in path at index 75