0

我正在使用以下使用 json 格式的 API 调用,但我没有得到任何格式的输出。我想知道的是如何使用 javacript 设置代理代码,以便我可以从跨服务器(另一台服务器)获取数据。是否还有其他可能接收/显示来自外国域的数据?iFrame 遵循相同的政策?这是我的 api 网址:api.wego.com/flights/api/k/2/searches?api_key=your_secret_api_key&ts_code=your_secret_ts_code

我想传递以下参数:{“trips”:[{“departure_code”:“SIN”,“arrival_code”:“HKG”,“outbound_date”:“2013-10-14”,“inbound_date”:“2013 -10-21" } ], "adults_count": 1 }

我正在使用下面的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://api.wego.com/flights/api/k/2/searches?api_key=xxxxxxxxx&ts_code=xxxxx');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json','Accept: application/json'));

$data = 
"trips": [
    {
      "departure_code": "SIN",
      "arrival_code": "HKG",
      "outbound_date": "2013-10-14",
      "inbound_date": "2013-10-21"
    }
  ],
  "adults_count": 1;

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$result=curl_exec($ch);
var_dump($result); 

谢谢

4

1 回答 1

0
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://api.wego.com/flights/api/k
      /2/searches?api_key=xxxxxxxxx&ts_code=xxxxx');
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type'=>'application/json',
        'Accept'=> 'application/json'));

$data ='{"trips":
     [ { "departure_code": "SIN", "arrival_code": "HKG",
           "outbound_date": "2013-10-14", "inbound_date": "2013-10-21" } ]
     , "adults_count": 1}';

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result=curl_exec($ch);
var_dump($result);
于 2013-12-17T09:44:41.843 回答