简体   繁体   English

java.net.URISyntaxException:索引 177 处的查询中存在非法字符

[英]java.net.URISyntaxException: Illegal character in query at index 177

I tried to get Azure Usage details via nextLink which is shared by Azure.我试图通过由 Azure 共享的 nextLink 获取 Azure 使用详细信息。 while i tried to make http request URISyntaxException is occured.当我试图使 http 请求发生 URISyntaxException 时。

HttpClient httpclient = getHttpClient();
          
URIBuilder uriBuilder=new URIBuilder(url);
HttpGet httpGet = new HttpGet(uriBuilder.build());
HttpResponse httpResponse = httpclient.execute(httpGet);

This is the nextLink url:这是下一个链接 url:

"https://management.azure.com/subscriptions/78c50b17-61fd-40cc-819c-4953586c7850/providers/Microsoft.Consumption/usageDetails?api-version=2019-11-01&$filter=properties/usageStart eq '2020-07-1' and properties/usageEnd eq '2020-07-30' &metric=actualcost&$expand=properties/meterDetails,properties/additionalInfo&sessiontoken=15:785628&$skiptoken=827CDTHDWI07C46616C7365730&skiptokenver=v1&id=2d790-d675-45d-89j56-3989w06cca" “https://management.azure.com/subscriptions/78c50b17-61fd-40cc-819c-4953586c7850/providers/Microsoft.Consumption/usageDetails?api-version=2019-11-01&$filter=properties/usageStart eq '202- 07-1' 和 properties/usageEnd eq '2020-07-30' &metric=actualcost&$expand=properties/meterDetails,properties/additionalInfo&sessiontoken=15:785628&$skiptoken=827CDTHDWI07C46616C7365730&skiptokenver=v1&id=2d790-d6675-4950d-cca98

I think this is because of characters such as?, & and.我认为这是因为诸如?、& 和等字符。 in my URL: so I tried using:在我的 URL 中:所以我尝试使用:

URLEncoder.encode(myUrl, "UTF-8"); URLEncoder.encode(myUrl, "UTF-8");

but after this, I faced protocol exception.但在此之后,我遇到了协议异常。

Am I missing something here?我在这里错过了什么吗?

Your URL contains spaces and single quotes, these should be URL encoded like you tried.您的 URL 包含空格和单引号,这些应该是 URL 编码的,就像您尝试过的一样。 However, because you tried to URL-encode the entire URL, you end up with this:但是,因为您尝试对整个URL 进行 URL 编码,所以您最终会得到以下结果:

https%3A%2F%2Fmanagement.azure.com%2Fsubscriptions%2F78c50b17-61fd-40cc-819c-4953586c7850%2Fproviders%2FMicrosoft.Consumption%2FusageDetails%3Fapi-version%3D2019-11-01%26%24filter%3Dproperties%2FusageStart+eq+%272020-07-1%27+and+properties%2FusageEnd+eq+%272020-07-30%27+%26metric%3Dactualcost%26%24expand%3Dproperties%2FmeterDetails%2Cproperties%2FadditionalInfo%26sessiontoken%3D15%3A785628%26%24skiptoken%3D827CDTHDWI07C46616C7365730%26skiptokenver%3Dv1%26id%3D2d790-d675-45d-89j56-3989w06cca

Which is not a valid URL.这不是有效的 URL。 You could simply try using a naive form of String replacement:您可以简单地尝试使用一种简单的字符串替换形式:

myUrl = myUrl.replace(" ", "%20").replace("'", "%27");

If that is not sufficient, you'll need to reconstruct the URL yourself, and only apply URL-encoding on the query parameter values.如果这还不够,您需要自己重建 URL,并且只对查询参数值应用 URL 编码。

暂无
暂无

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

相关问题 java.net.URISyntaxException:JMETER 索引处的查询中存在非法字符 - java.net.URISyntaxException: Illegal character in query at index on JMETER JMeter - Java.net.URISyntaxException:索引路径中的非法字符 - JMeter - Java.net.URISyntaxException: Illegal character in path at index java.net.URISyntaxException:索引75处路径中的非法字符 - java.net.URISyntaxException: Illegal character in path at index 75 java.net.URISyntaxException:带有jmeter的索引处的路径中的非法字符 - java.net.URISyntaxException: Illegal character in path at index with jmeter Jmeter Http 代理服务器抛出 java.net.URISyntaxException: Illegal character in query at index 错误 - Jmeter Http proxy server throws java.net.URISyntaxException: Illegal character in query at index error 由以下原因导致:java.net.URISyntaxException:索引111处的查询中的非法字符:错误是由于URI中的{} - Caused by: java.net.URISyntaxException: Illegal character in query at index 111 : Error Beacuse of {} in URI Apache Spark:线程“ main”中的异常java.net.URISyntaxException:索引0处路径中的非法字符: - Apache Spark: Exception in thread “main” java.net.URISyntaxException: Illegal character in path at index 0: java.net.URISyntaxException - java.net.URISyntaxException java.net.URISyntaxException:在Weblogic中部署War时索引69处的字符无效 - java.net.URISyntaxException:Invalid character at index 69 when deploying war in weblogic java.net.URISyntaxException:索引7的预期权限:http:// - java.net.URISyntaxException: Expected authority at index 7: http://
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM