2017-08-02 64 views
1

我目前正在使用PHP的網站上工作。 我想要像Ruby代碼如下所示的一個GET請求:Ruby獲取請求到PHP獲取請求

response = RestClient::Request.execute(
:method => :get, 
:url  => 'https://api.place2book.com/event_api/available_tickets', 
:timeout => 5, 
:headers => { 
'X-PLACE2BOOK-API-TOKEN' => 'foobar789baz7674', 
'X-PLACE2BOOK-EVENT-ID' => 123456 
} 
) 

response.headers[:available_tickets] 

但是我不知道很多API獲取請求在PHP。

+0

您可以使用捲曲爲,或使用庫更喜歡狂飲functionnality:http://docs.guzzlephp.org – yoeunes

回答

0

我建議使用狂飲:

http://docs.guzzlephp.org/en/stable/

$client = new GuzzleHttp\Client(); 
$res = $client->request('GET', 'https://api.github.com/user', [ 
    'auth' => ['user', 'pass'] 
]); 
echo $res->getStatusCode(); 
// "200" 
echo $res->getHeader('content-type'); 
// 'application/json; charset=utf8' 
echo $res->getBody(); 
// {"type":"User"...' 
+0

狂飲似乎是有益並沒有在鏈接的文章中提到。你還可以在那裏添加這個答案(因爲這個問題更具可讀性)? –

+0

然後你可以刪除這個。 –