【问题标题】:Fatal error: Call to undefined function http_get()致命错误:调用未定义函数 http_get()
【发布时间】:2015-02-28 19:12:04
【问题描述】:

我尝试使用 http_get 在 php 编码中发出跨域请求。在我的服务器中,没有安装必需的模块。我不知道要安装什么才能使 http_get 成为可能。

我得到的错误是

致命错误:调用未定义的函数 http_get() C:\xampp\htdocs\article\index.php 在第 2 行

我尝试这样做 (PECL pecl_http >= 0.1.0) http_get — 执行 GET 请求

但是,我没有找到解决办法。

所以,请帮我运行 http_get 编码。提前致谢。

【问题讨论】:

    标签: php cross-domain


    【解决方案1】:

    我认为您必须在您的 php.ini 文件中启用 extension=php_http.dll,然后重新启动您的 Apache 服务器。
    我建议您使用 cURL 而不是 http_get()(同样的操作,您必须启用 extension=php_curl.dll 并重新启动 apache)

    希望有所帮助:)

    【讨论】:

    • 出于好奇,您为什么建议他们改用 cURL?
    • @Halayem 你能举一个 cURL 的使用例子吗? http_get() 仍未定义。
    【解决方案2】:

    要直接回答问题,你必须在php.ini 中启用extension=php_http.dll 并重新启动apache,但在我们的时代绝对不需要使用http_get()

    这里有 3 个不错的选择:

    1. phpcurl
    2. file_get_contents()
    3. copy()

    Curl 用法:

    // Get cURL resource
    $curl = curl_init();
    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => 'http://testcURL.com/?item1=value&item2=value2',
        CURLOPT_USERAGENT => 'User Agent X'
    ));
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    // Close request to clear up some resources
    curl_close($curl);
    

    file_get_content() 用法:

    $my_var = file_get_contents("https://site/");
    

    copy() 用法:

    copy("https://site/image.png", "/local/image.png");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 2012-07-18
      • 2017-01-25
      • 2012-06-28
      • 2014-03-27
      相关资源
      最近更新 更多