如何将未编码的QueryParameters添加到HttpUrl?

时间:2019-06-04 10:22:30

标签: okhttp3 google-geocoder google-geocoding-api

要使用Google的地理编码APIv3对地址进行地理编码,我想构建一个等于以下内容的HttpUrl: <div class="container-fluid"> <div id="masonry"> @foreach (var image in Model) { <div class="item"> <div class="overlay"> <button type="button" class="btn btn-dark">Favorite</button> </div> <img src="~/images/thumbnails/@image.Name" class="img-fluid" /> </div> } </div> </div>

编码的查询参数#masonry { column-count: 3; column-gap: 1em; } @media(min-width: 40em) { #masonry { column-count: 4; column-gap: 1em; } } .item { display: inline-block; margin: 0 0 1em 0; width: 100%; cursor: pointer; } .item img { position: relative; max-width: 100%; height: auto; width: 100%; margin-bottom: -4px; } .item:hover { opacity: 0.8; } .item:hover .overlay { opacity: 1; } .overlay { position: absolute; top: 50%; left: 50%; opacity: 0; transition: .5s ease; } 将导致对邮政编码的预期过滤失败(see this thread)。

我需要在URL的components参数之后的/中加一个等号和一个双点,而不是%3D和%3A。

是否可以使用OkHttp3做到这一点?

我尝试使用方法https://maps.googleapis.com/maps/api/geocode/json?address=Gaustraße 200, Worms&key=...&components=postal_code:67547components%3Dpostal_code添加查询参数

addQueryParameter

在两种情况下,组件和邮政编码之间的“ =”均已编码,因此URL如下所示:

addEncodedQueryParameter

如上所述,这将导致Google省略对结果的过滤。

0 个答案:

没有答案