簡體   English   中英

如何使用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#requests

http://guzzle.readthedocs.org/en/latest/clients.html#sending-requests

有關自定義標題,請參見:

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

Guzzle功能強大且易於使用,並且可以嘗試許多“復制粘貼”示例:)


Symfony2 Guzzle作曲家軟件包:

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

Laravel的request對象只是擴展了Symfony的HTTP請求類(並添加了一些Laravel特定的方法),因此,您可以使用Symfony\\Component\\HttpFoundation\\Request都可以使用Laravel的request類進行處理。

您是對的,可以使用Request::create() 請參閱Symfony文檔中的此部分: http : //symfony.com/doc/current/components/http_foundation/introduction.html#simulating-a-request

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM