简体   繁体   English

如何在PHP中使用Curl使用Hub API

[英]How to use Hub API using Curl in php

I have purchase Hub API from RouteHappy website for search flights using Source and Destination. 我已经从RouteHappy网站购买了Hub API,用于使用“来源”和“目的地”进行搜索航班。

They give me below code for using their API 他们给我下面使用API​​的代码

curl \
  -H "Auth: YOUR_API_KEY" \
  -H "Accept: application/vnd.api.v3+json" \
  -G \
  -d ids=DSM-ORD-AA-3558-20160907-FIRST \
  -d include=seat,wifi \
  YOUR_HOST/segments

But I am not able to use Flight API using Curl in PHP, Laravel.Please help me out to access API and get desire result. 但是我无法使用PHP,Laravel中的Curl使用Flight API。请帮助我访问API并获得期望的结果。

the equivalent using hhb_curl would be 使用hhb_curl的等效

echo (new hhb_curl ( '', true ))->setopt_array ( array (
        CURLOPT_URL => 'YOUR_HOST/segments',
        CURLOPT_HTTPHEADER => array (
                "Auth: YOUR_API_KEY",
                "Accept: application/vnd.api.v3+json" 
        ),
        CURLOPT_POSTFIELDS => http_build_query ( array (
                'ids' => 'DSM-ORD-AA-3558-20160907-FIRST',
                'include' => 'seat,wifi' 
        ) ) 
) )->exec ()->getStdOut ();
  • and the equivalent using the native curl_ api would be very much like that, but with a lot more manual labour (checking return types of setopt and exec, and creating a temporary output file for curl, cleaning up the resources/memory of the temp file and curl when you're finished, etc, all of which hhb_curl does for you automatically. and curl errors are converted to RuntimeExceptions ) 而使用本机curl_ api进行的等效操作非常类似,但是需要更多的人工(检查setopt和exec的返回类型,并为curl创建一个临时输出文件,清理临时文件的资源/内存和卷曲,当您完成等操作时,hhb_curl会自动为您完成所有操作。并且curl错误将转换为RuntimeExceptions

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

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