PHP REST客户端 [英] PHP REST Clients
问题描述
我试图连接到RESTful Web服务,但是遇到了一些麻烦,尤其是在通过PUT和DELETE发送数据时.使用cURL,PUT需要发送文件,而DELETE只是很奇怪.我完全有能力使用PHP的套接字支持编写客户端并自己编写HTTP标头,但我想知道你们是否曾经使用过或看到过PHP的REST客户端?
I'm trying to connect to a RESTful web service, but I'm having some troubles, especially when sending data over PUT and DELETE. With cURL, PUT requires a file to send, and DELETE is just weird. I'm perfectly capable of writing a client using PHP's socket support and writing the HTTP headers myself, but I wanted to know whether you guys have ever used or seen a REST client for PHP?
推荐答案
事实证明,Zend_Rest_Client根本不是REST客户端-例如,它不支持PUT和DELETE方法.在尝试使其与实际的RESTful服务一起使用后,我受够了,并为PHP编写了适当的REST客户端:
So as it turns out, Zend_Rest_Client isn't a REST client at all — it does not support the PUT and DELETE methods for example. After trying to kludge it into working with an actual RESTful service I got fed up and wrote a proper REST client for PHP:
http://github.com/educoder/pest
它仍然缺少一些东西,但是如果它被拾起,我会做更多的工作.
It's still missing a few things but if it gets picked up I'll put some more work into it.
这是OpenStreetMap REST服务的用法示例:
Here's a usage example with the OpenStreetMap REST service:
<?php
/**
* This PestXML usage example pulls data from the OpenStreetMap API.
* (see http://wiki.openstreetmap.org/wiki/API_v0.6)
**/
require_once 'PestXML.php';
$pest = new PestXML('http://api.openstreetmap.org/api/0.6');
// Retrieve map data for the University of Toronto campus
$map = $pest->get('/map?bbox=-79.39997,43.65827,-79.39344,43.66903');
// Print all of the street names in the map
$streets = $map->xpath('//way/tag[@k="name"]');
foreach ($streets as $s) {
echo $s['v'] . "\n";
}
?>
当前它使用curl,但我可以将其切换到HTTP_Request或HTTP_Request2.
Currently it uses curl but I may switch it to HTTP_Request or HTTP_Request2 down the line.
更新:似乎有很多人对此表示欢迎.由于GitHub上的贡献者,Pest现在支持HTTP身份验证和许多其他功能.
Update: Looks like quite a few people have jumped on this. Pest now has support for HTTP authentication and a bunch of other features thanks to contributors on GitHub.
这篇关于PHP REST客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!