android 获取网络重定向URL

android 获取网络重定向URL,第1张

概述直接上代码:importjava.net.HttpURLConnection;importjava.net.URL;importorg.junit.Assert;importorg.junit.Test;publicclassGetRedirectUrlTest{@Testpublicvoidtest_getRedirectUrl()throwsException{Stringurl="http://www.baidu.

直接上代码:

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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1036873.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存