2010-12-05 49 views
0

这是zend代码。如何将其转换为泛型PHP?在php中有什么等价物?

$client = New Zend_Http_Client(); 
$client->setUri('http://someurl.com/somepage'); 

$request = $client->request(); 

if ($request->isSuccessful()) { 
//do stuff with the result 
} 

回答

6
$page = file_get_contents('http://someurl.com/somepage'); 
+0

哪个不能在大多数共享主机上运行:)您应该使用cURL来替代,正如Ignacio指出的那样。 – takeshin 2010-12-07 17:13:18

2

在PHP中,你可以随便抓一个URI与get_file_contents($网址)中的内容,甚至的fopen($网址, 'R')等

您可以设置使用stream_context_create流参数(),然后在该上下文中使用fopen(),如果你想控制像HTTP请求方法,用户代理,代理,超时,如何处理错误等。

cURL是一种替代方法,也可以给你更大的控制权 - 但是,这又增加了另一种依赖性。

相关问题