gpt4 book ai didi

android - 从完整 url 中提取基本 url

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:28 25 4
gpt4 key购买 nike

从完整 url 中提取基本 url 的任何快速方法?例如,如果我有 http://test.example.com/abcd/test.html - 我只想要 http://test.example.com .

我总是可以进行字符串解析 - 但想知道 Uri 中是否有我可以直接获取的内容。

最佳答案

关于:

import java.net.URL;
import java.net.MalformedURLException;

try
{
URL url = new URL("http://test.example.com/abcd/test.html");
String baseUrl = url.getProtocol() + "://" + url.getHost();
}
catch (MalformedURLException e)
{
// do something
}

关于android - 从完整 url 中提取基本 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4492944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com