【发布时间】:2017-04-19 00:16:03
【问题描述】:
TIA 为您提供帮助。
我正在使用 cURL 调用外部 REST API。通话效果很好。
作为 cURL 选项的一部分,我使用 CURLOPT_HEADERFUNCTION 来解析响应标头,如下所示:
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "parseResponseHeaders");
函数看起来像这样:
function parseResponseHeaders($ch, $header_line ) {
if(preg_match("/Location/i", $header_line)){
$break_header = explode(": ", $header_line);
$build_new_string = $break_header[1].$string_from_outside_this_function;
}
return strlen($header_line);
}
我遇到的问题是“$string_from_outside_this_function”变量返回未定义。
我了解“parseResponseHeaders”回调接受 2 个参数。所以我不能传递外部变量。
我假设外部变量不在范围内。但是,上面的代码包含在父函数(方法)中。
并且外部变量在父函数内的任何其他地方都可用。
不知道我做错了什么。
谢谢。
【问题讨论】: