我有例如网址http://example.com/{x}/push/{y}
。
我正在使用OkHttp对该网址进行查询。
final HttpUrl httpUrl = HttpUrl
.parse("http://example.com/{x}/push/{y}")
.newBuilder()
???
.build();
是否有可能以某种方式设置{x}
和{y}
路径参数?
我看到像addPathSegment
这样的方法,但这不是我想要的。
答案 0 :(得分:0)
这是一种可以帮助您入门的技术。
<style type="text/css">
.ms-core-listMenu-horizontalBox li.static > a{
display: none !important;
}
.ms-core-listMenu-horizontalBox li.static > ul a{
display: block !important;
}
</style>
答案 1 :(得分:0)
也许HttpUrl.setPathSegment(index, value)
可以使它看起来更好一些:D
答案 2 :(得分:0)
fun HttpUrl.insertPathSegment(index: Int, pathSegment: String): HttpUrl {
val newPathSegments: ArrayList<String> =
encodedPathSegments().fold(ArrayList()) { acc, oldPathSegment ->
printLog("OkHttp", "insertPathSegment oldPathSegment:$oldPathSegment ")
acc.add(oldPathSegment)
acc
}
return newBuilder().apply {
try {
newPathSegments.add(index, pathSegment)
addEncodedPathSegment("")
newPathSegments.forEachIndexed { index, path ->
printLog("OkHttp", "insertPathSegment setEncodedPathSegment:$index $path ")
setEncodedPathSegment(index, path)
//printLog("OkHttp", "insertPathSegment setPathSegment:$index $path ")
//setPathSegment(index, path)
}
} catch (e: Exception) {
e.printStackTrace()
}
}.build()}