我正在使用来自http://phphttpclient.com/的 Httpful PHP库,这是我的示例代码:
$data = array(
'code' => $request->query->get('code'),
'client_id' => $this->container->getParameter('GOOGLE_CLIENT_ID'),
'client_secret' => $this->container->getParameter('GOOGLE_CLIENT_SECRET'),
'redirect_uri' => $google_redirect,
'grant_type' => "authorization_code"
);
$response = Request::post($url)->body($data)->sendsType(Mime::FORM)->send();
var_dump($response);
die();
Run Code Online (Sandbox Code Playgroud)
我的问题是如何添加表单数据.我试图阅读文档,但我找不到任何解释,只有发送xml和Json示例,但我无法在请求中获得表单数据的正常POST.
有人请帮帮我..
我需要通过Rest上传文件,并发送一些配置.
这是我的示例代码:
$this->login();
$files = array('file'=>'aTest1.jpg');
$data =
array(
'name'=>'first file',
'description'=>'first file description',
'author'=>'test user'
);
$response = Request::post($this->getRoute('test'))
->addHeader('Authorization', "Bearer " . $this->getToken())
->attach($files)
->body(json_encode($data))
->sendsJson()
->send();
Run Code Online (Sandbox Code Playgroud)
我能够发送文件或能够发送正文.但如果我尝试两者都不行......
有什么提示吗?
问候n00n
我正在尝试学习 REST,并认为从 PHP REST 客户端(例如 Httpful)开始可能会很好。我似乎无法让它发挥作用。我下载了 httpful.phar 文件并将其放在我的工作目录中。然后创建了一个简单的 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";
?>
Run Code Online (Sandbox Code Playgroud)
我在网站上尝试了多个示例,但在我的浏览器中加载它时只得到一个空白页面。
谢谢你提供的所有帮助!
从http://phphttpclient.com我按照"安装选项1"和第一个"快速片段".
我最终得到以下内容,请求未定义.


另外,也许是相关的,我对其中一个代码示例说"$ response = Request :: get"而另一个代表"$ response =\Httpful\Request :: get"这一事实感到困惑.后者是有效的PHP吗?
我有PHP 5.6.7.

我究竟做错了什么?
我已经安装了Httpful,如Composer中所述添加到composer.json中:
{
"require": {
"nategood/httpful": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Laravel 4所以我跑了composer install
我已经检查了插件是否安装并且在那里,实际上在laravel的供应商文件夹下我可以找到它.但我不断收到以下错误:
ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Httpful' not found'
Run Code Online (Sandbox Code Playgroud)
我错过了一些步骤?
先感谢您