简体   繁体   English

如何使用Httpful PHP库

[英]How to use Httpful PHP Library

I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. 我正在尝试学习REST,并认为从PHP REST客户端(例如Httpful)开始可能会很好。 I just can't seem to get it to work. 我似乎无法正常工作。 I downloaded the httpful.phar file and placed it in my working directory. 我下载了httpful.phar文件并将其放在我的工作目录中。 Then created a simple php file with the following contents from an example on the their site : 然后在其网站上的示例中创建了一个包含以下内容的简单php文件:

<?php
// Point to where you downloaded the phar
include('httpful.phar');

$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();

echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>

I've tried multiple examples on the site, but only get a blank page when I load it in my browser. 我已经在该网站上尝试了多个示例,但是当我将其加载到浏览器中时,只会得到一个空白页。

Thanks for any help you can give! 谢谢你提供的所有帮助!

This library uses Namespaces. 该库使用命名空间。 Either use a complete classname or use the class 使用完整的类名或use

With a complete Classname: 具有完整的类名:

\Httpful\Request::get($uri)->send();

With a use: 配合使用:

use Httpful\Request;
Request::get($uri)->send();

The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar. 遗憾的是,该示例代码在网站上非常不完整,但是您可以从主题“安装选项1:PHAR”下的示例或phar中的实际源代码中获得提示。

http://phphttpclient.com/ http://phphttpclient.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM