0

example.com 网址

我打电话给这个网址,但得到jsonCallback({"ERROR": "6"});. 我无法理解这是什么。我已经多次搜索错误,但找不到任何有用的信息。

这是一个网站,通过调用这个 url 我会得到价目表。当我从网站本身调用它时,我正在正确获取数据。但是每当我要复制 http 请求并将其粘贴到 url 时,它都会显示错误。

以下是我的 CURL 请求:

<?php

   class CURL {
   var $callback = false;

function setCallback($func_name) {
    $this->callback = $func_name;
}

function doRequest($method, $url, $vars) {
    $headers=array();
    $headerVar=0;
    $headers[$headerVar]='Content-Type: text/javascript; charset=UTF-8';    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);       
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    if ($method == 'POST') {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
    }
    $data = curl_exec($ch);
    curl_close($ch);

    echo '<br><br>'.curl_error().'-----'.curl_error();
    return $data;

    if ($data) {
        if ($this->callback)
        {
            $callback = $this->callback;
            $this->callback = false;
            return call_user_func($callback, $data);
        } else {
            return $data;
        }
    } else {
        return curl_error($ch);
    }
}

function get($url) {
    return $this->doRequest('GET', $url, 'NULL');
}

function post($url, $vars) {
    return $this->doRequest('POST', $url, $vars);
}
  }


      function stringParameter($array)  {
    $post_items=array();
    foreach ( $array as $key => $value) {
        $post_items[] = $key . '=' . $value;
    }
    //create the final string to be posted using implode()
    $post_string = implode ('&', $post_items);
    return $post_string;
      }

     function build_http_query( $query ){

    $query_array = array();

    foreach( $query as $key => $key_value ){


        if($key_value != ''){
            $query_array[] = urlencode($key) . '=' . urlencode( $key_value );
        }else {
            $query_array[] = urlencode($key) . '=' .  $key_value ;
        }
    }

    return htmlspecialchars(implode( '&', $query_array ));

     }

        list($usec, $sec) = explode(" ", microtime()); 
      $time13 = sprintf('%d%03d', $sec, $usec/1000); 

       $data    =   
    array(
        "brand" => "PERODUA",
        "model" => "VIVA 1.0",
        "gender" => "Male",
        "md_age" => '35',
        "marital_status" => "Married",
        "car_age" => '8',
        "ncd" => '0',
        "data" => 
                        array(
                        "car_data" => array( 
                                                           "make"=>"PERODUA", 
                                        "model"=>"VIVA 1.0", 
                                        "year_of_manufacture"=>"2004", 
                                        "offpeak"=>"yes"    
                                    ),
                        "drivers_data" => array( 
                                        "driver_1"=>    array(
                                                "gender"                => "Male",
                                                "marital_status"        => "Married",
                                                "date_of_birth"         => "22/3/1978",
                                                "year_driving_license"  => "1999",
                                                "ncd"                   => "0",
                                                "occupation"            => "ZADM: Indoor Office/Exec/Admin Staff",
                                                "relationship"          => " "
                                        )       
                                    ),
                        "discount_data" => array(
                                        "certificate_of_merit" => false
                                    ),
                        "claims_data" => array(
                                        "have_claims"   => "no",
                                        "claims_number" => "0",
                                        "claims_amount" => "0"
                                    ),
                        "product_data" =>  array(
                                        "plan"  => null,
                                        "price" => null,
                                        "policy_start"=> "1/5/2013",
                                        "policy_end"=> "30/4/2014",
                                            "ncd"=> false,
                                             "excess"=> null
                                    )                       
                        ) 
        );              

   $encode = build_http_query($data);
$url = 'https://example.com/price?callback=jsonCallback&'.$encode;  
$obj = new CURL();
echo $ppp =  $obj->get($url);


 ?>

我在 url 中发送数据是错误的,因为它是用 json 编写的吗?

4

2 回答 2

0

尝试使用,build_http_queryhttp_build_query

于 2013-05-18T09:02:52.517 回答
0

{"ERROR": "6"} 消息是https://axasingaporemotor.appspot.com/price返回的自定义错误消息

您需要联系该 URL 的所有者,以了解错误 6 的含义。

于 2013-05-18T08:54:33.763 回答