
直接上代码:
import java.net.httpURLConnection;import java.net.URL;import org.junit.Assert;import org.junit.Test;public class GetRedirectUrlTest { @Test public voID test_getRedirectUrl() throws Exception { String url="http://www.baIDu.com/link?url=ByBJLpHsj5nXx6DESXbmMjIrU5W4Eh0yg5wCQpe3kCQMlJK_RJBmdEYGm0DDTCoTDGaz7rH80gxjvtvoqJuYxK"; String expectUrl="http://www.zhihu.com/question/20583607/answer/16597802"; String redictURL = getRedirectUrl(url); Assert.assertEquals(expectUrl, redictURL); } /** * 获取重定向地址 * @param path * @return * @throws Exception */ private String getRedirectUrl(String path) throws Exception { httpURLConnection conn = (httpURLConnection) new URL(path) .openConnection(); conn.setInstanceFollowRedirects(false); conn.setConnectTimeout(5000); return conn.getheaderFIEld("Location"); }} 总结 以上是内存溢出为你收集整理的android 获取网络重定向URL全部内容,希望文章能够帮你解决android 获取网络重定向URL所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)