我在一些旧脚本中使用以下命令:
curl -Lk "https:www.example.com/stuff/api.php?"然后,我将标题记录到一个变量中,并进行比较等等。我真正想做的是将这个过程转换成PHP。我已经启用了curl、openssl,并且相信我已经做好了一切准备。
我似乎找不到一种方便的翻译方法,可以将命令行语法转换为PHP中的等效命令。
我怀疑有些事情是这样的:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// What goes here so that I just get the Location and nothing else?
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch); 目标是$response =来自“OK=1&ect”接口的数据
谢谢
发布于 2010-11-17 04:50:01
我被你的评论搞糊涂了:
// What goes here so that I just get the Location and nothing else?无论如何,如果您想要从远程服务器获取响应正文,请使用:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);如果您想要获取响应中的头部(即:您的评论可能引用的内容):
curl_setopt($ch, CURLOPT_HEADER, 1);如果您的问题是在初始调用和响应之间存在重定向,请使用:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);https://stackoverflow.com/questions/4198693
复制相似问题