如何使用POST或PUT调用API


How to call API using POST or PUT

我需要通过带有自定义头和自定义HTTP谓词的HTTP请求调用API

PUT: http://www.example.com/system/get_user_categories/format/json/user_id/**10**

我想我需要使用:

request::create

但我不知道怎么做。

对于此任务,您可以使用"Guzzle" PHP-HTTP-Client。

发送请求GET,POST,PUT,DELETE…

http://guzzle.readthedocs.org/en/latest/http-messages.html请求

http://guzzle.readthedocs.org/en/latest/clients.html发送请求

自定义标头参见:

http://guzzle.readthedocs.org/en/latest/http-messages.html头

Guzzle功能强大且易于使用,并且有很多"复制粘贴"的例子可以尝试:)


Symfony2 Guzzle composer-package:

https://packagist.org/packages/guzzle/guzzle

Laravel的请求对象只是扩展了Symfony的HTTP请求类(并添加了一些Laravel特定的方法),所以你可以用Symfony'Component'HttpFoundation'Request做的任何事情都可以用Laravel的请求类做。

你是对的,你可以使用Request::create()。请参阅Symfony文档中的本节:http://symfony.com/doc/current/components/http_foundation/introduction.html#simulating-a-request