远程服务器上的json响应无效

时间:2015-12-05 19:15:57

标签: php json curl

我有一个非常奇怪的问题,我一直试图弄清楚2天,我有以下代码从网站获取航班信息的信息,它在我的localhost完美运行并返回我" { {1}}"但是当我在我的服务器上上传脚本时,它会返回一个" {thedata:what_I_Need}"来自网站的错误。

我尝试了4个不同的液滴/ vps,每个都在不同的国家IP中,具有相同的配置(与我的本地计算机相同的curl-php-apache版本和模块)(使用带有php5的ubuntu 14.4)但它仍然具有同样的问题。这是在localhost上完美运行的代码:

{invalid:true}

我也关注了this文章,但即使我用

替换 $url = 'http://site.url.com'; $post = array( 'LanguageID' => 2, 'Trips' => array(array( 'Origin' => "JFK", 'Destination' => "TEX", 'Departure' => "2015-12-24T00:00:00", )), 'Return' => "2015-12-28T00:00:00", 'Carriers' => null 'Adults' => 1, 'Children' => 0 ); $data_string = json_encode($post); $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); curl_setopt($ch,CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($ch, CURLOPT_REFERER, "http://www.site.url.com"); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Length: ' . strlen($data_string)) ); curl_setopt($ch, CURLOPT_COOKIE, $cookie); $output=curl_exec($ch); curl_close($ch); ,我仍然在远程网站上遇到同样的问题
CURLOPT_POST

0 个答案:

没有答案