V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Adia
V2EX  ›  Java

模拟 HttpPost 请求发送后,对面重定向了,如何获取其 URL?

  •  
  •   Adia · 2016-11-25 10:50:49 +08:00 · 3598 次点击
    这是一个创建于 2710 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原帖在这里

    先谢过为敬!

    6 条回复    2016-11-25 16:10:00 +08:00
    scnace
        1
    scnace  
       2016-11-25 12:56:25 +08:00
    从 CookieJar 里拿(不造 Java 里面有没有
    nicevar
        2
    nicevar  
       2016-11-25 13:07:51 +08:00
    location 里面找
    yidinghe
        3
    yidinghe  
       2016-11-25 13:10:47 +08:00 via Android
    http header 里面有重定向地址,楼主不妨顺便了解下 http 协议相关知识
    eoo
        4
    eoo  
       2016-11-25 15:15:56 +08:00 via Android
    想抓包看看是从 header 跳 还是从 js 跳
    missdeer
        5
    missdeer  
       2016-11-25 15:41:50 +08:00 via Android
    http client 应该有设置不自动重定向的选项,每次重定向时调用你的回调之类的
    xsh
        6
    xsh  
       2016-11-25 16:10:00 +08:00
    php curl 取最终地址的方式,可以做一个参考(前提是结果中有 header 头信息):

    $content = curl_exec($ch);
    $retVal = array();
    $fields = explode("\r\n", @preg_replace_callback('/\x0D\x0A[\x09\x20]+/', 'a', $content));
    foreach( $fields as $field ) {
    if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
    $match[1] = @preg_replace_callback('/(?<=^|[\x09\x20\x2D])./', 'b', strtolower(trim($match[1])));
    if( isset($retVal[$match[1]]) ) {
    $retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
    } else {
    $retVal[$match[1]] = trim($match[2]);
    }
    }
    }
    if(!is_array($retVal)) {
    return false;
    }
    return $retVal['location'];
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2817 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 12:23 · PVG 20:23 · LAX 05:23 · JFK 08:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.