【问题标题】:cant resolve httprequest fatal error无法解决 http 请求致命错误
【发布时间】:2014-05-04 09:37:23
【问题描述】:

我正在尝试在 php 中创建服务器端页面,我必须通过 http 请求从某个网站获得响应。 我收到错误 HttpRequest not found。 试图修复这个错误我能够找到用于 http 请求的 php_http.dll 文件。我已将它添加到 php 扩展文件夹 /ext 现在我也可以在扩展列表中看到它。 但问题是我仍然有同样的错误...... 现在我明白的是,可能是 php_http 文件版本较旧.. 我有 php 5.4.16 32bit,我能找到的最高版本 dll 文件是 5.3 我在哪里可以找到兼容的版本。 或者告诉我我是否已经做错了什么......

$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_POST);

这是我正在努力消除错误的代码行

【问题讨论】:

    标签: php


    【解决方案1】:

    在php中使用cURL

    <?php
    // A very simple PHP example that sends a HTTP POST to a remote site
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,"http://example.com/feed.rss");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,"postvar1=value1&postvar2=value2");
    
    // in real life you should use something like:
    // curl_setopt($ch, CURLOPT_POSTFIELDS, 
    //          http_build_query(array('postvar1' => 'value1')));
    
    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $server_output = curl_exec ($ch);
    
    curl_close ($ch);
    
    // further processing ....
    if ($server_output == "OK") { ... } else { ... }
    
    ?>
    

    更多信息请看PHP Difference between Curl and HttpRequest

    【讨论】:

    • 我试过你的方法它给未定义函数 curl_init() 的调用错误
    • 是的,你必须启用 curl 默认情况下它没有启用看到这个stackoverflow.com/questions/1347146/… 或者如果你使用 wamp,点击任务栏上的 wamp 图标 => 然后点击 PHP =>php 扩展=> php_curl
    • 我现在遇到了另一个问题...最终将此地址更改为 youtube.com 而不是 example.com什么都没有。。它是空白的。应该假设发生了吗?
    • 那是因为 youtube 不允许你提出这个请求,代码没问题
    【解决方案2】:

    我不会为此使用 HttpRequest。我会简单地使用 curl_init()。但是,您需要确保您的机器中安装了 php-curl 库。

    【讨论】:

    • 看起来我没有你说的那个库......我怎么能安装那个库
    • 如果是 Ubuntu 或基于 Debian 的 linux,我会执行 sudo apt-get install php5-curl 。如果使用Windows,请查看this
    猜你喜欢
    • 2019-07-26
    • 2013-03-17
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 2011-02-22
    相关资源
    最近更新 更多