【问题标题】:get request for a website in a php script在 php 脚本中获取对网站的请求
【发布时间】:2016-02-11 10:16:48
【问题描述】:

我想在这样的网站上收到请求

$id = "something";
$response = http_get("http://example.com?id=$id, array("timeout"=>1), $out);

我不知道如何使用 http_get

我已经尝试过使用 file_get_contents,它的工作原理就像

$out = file_get_contents("http://www.example.com?id=something");

但我想要那样

$out = file_get_contents("http://www.example.com?id=$id");

这个不行

【问题讨论】:

  • 你看过http_get的手册页吗?
  • 我看到了但是没处理
  • 也许试试这个http_get("http://example.com?id=$id", array("timeout"=>1), $out); 注意:语法错误。
  • 你想要什么(“响应”是什么意思)。你想要头部、身体、头部+身体还是原始网络响应(可以压缩)?
  • 我只是想身体,我只是尝试了我在手册页中看到的内容

标签: php file-get-contents http-get get-request


【解决方案1】:

我让它工作的方式是使用下面的代码。

$out = file_get_contents("http://www.example.com?id=".$id);

这会将 $id 变量内容连接到要请求的 url 的末尾。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    相关资源
    最近更新 更多