V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  xsh  ›  全部回复第 1 页 / 共 1 页
回复总数  2
2016-11-25 16:10:00 +08:00
回复了 Adia 创建的主题 Java 模拟 HttpPost 请求发送后,对面重定向了,如何获取其 URL?
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'];
2016-10-11 17:24:09 +08:00
回复了 yuanchao 创建的主题 PHP 目前有哪些扩展不支持 php 7 ?
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2752 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 05:43 · PVG 13:43 · LAX 22:43 · JFK 01:43
Developed with CodeLauncher
♥ Do have faith in what you're doing.