无法解决http请求致命错误

时间:2014-03-26 06:37:49

标签: php

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

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

这是我正在努力从

中删除错误的代码行

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我不会为此使用HttpRequest。我只想使用curl_init()。但是,您需要确保在计算机中安装了php-curl库。