php - JSON POST Request - JSON data, How to do a post request with data in JSON format on cross server with proxy request -
i using following api call using json format not getting output in format. want know how can set proxy code javacript , can data cross server(another server). there other possibility receive/display data foreign domain ? iframes follow same policy? here api url: api.wego.com/flights/api/k/2/searches?api_key=your_secret_api_key&ts_code=your_secret_ts_code
and want pass below parameter: { "trips": [ { "departure_code": "sin", "arrival_code": "hkg", "outbound_date": "2013-10-14", "inbound_date": "2013-10-21" } ], "adults_count": 1 }
and using below code:
$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);
thanks
$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);
Comments
Post a Comment