gpt4 book ai didi

java - 在 Java 中解析到其目标 URL 的缩短链接的最快方法是什么?

转载 作者:行者123 更新时间:2023-11-29 09:50:45 25 4
gpt4 key购买 nike

哪个库或内置功能可以让您使用 bitly、fb.me、google 的缩短器等缩短的 URL 并在最快的时间内获得其最终链接?

谢谢

最佳答案

programming time mostly, I'm using httpclient from apache right now wondering if their are any alternatives built in

java.net.URLConnection .

String location = "http://tinyurl.com/so-hints";
HttpURLConnection connection = (HttpURLConnection) new URL(location).openConnection();
connection.setInstanceFollowRedirects(false);
while (connection.getResponseCode() / 100 == 3) {
location = connection.getHeaderField("location");
connection = (HttpURLConnection) new URL(location).openConnection();
}
System.out.println(location); // http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx

关于java - 在 Java 中解析到其目标 URL 的缩短链接的最快方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505358/

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