[英]java.net.URISyntaxException: Illegal character in query at index on JMETER
[英]java.net.URISyntaxException: Illegal character in query at index 177
我试图通过由 Azure 共享的 nextLink 获取 Azure 使用详细信息。 当我试图使 http 请求发生 URISyntaxException 时。
HttpClient httpclient = getHttpClient();
URIBuilder uriBuilder=new URIBuilder(url);
HttpGet httpGet = new HttpGet(uriBuilder.build());
HttpResponse httpResponse = httpclient.execute(httpGet);
这是下一个链接 url:
“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
我认为这是因为诸如?、& 和等字符。 在我的 URL 中:所以我尝试使用:
URLEncoder.encode(myUrl, "UTF-8");
但在此之后,我遇到了协议异常。
我在这里错过了什么吗?
您的 URL 包含空格和单引号,这些应该是 URL 编码的,就像您尝试过的一样。 但是,因为您尝试对整个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
这不是有效的 URL。 您可以简单地尝试使用一种简单的字符串替换形式:
myUrl = myUrl.replace(" ", "%20").replace("'", "%27");
如果这还不够,您需要自己重建 URL,并且只对查询参数值应用 URL 编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.