How do you read API postcalc?



  • I'm writing a php crypt asking curl to http://www.postcalc.ru/api.html to get the cost of delivery.

    This is the function:

    function methodCurl($to,$weight,$price) {   
    
    $baseUrl = "http://api.postcalc.ru/?";
    $baseUrl .= $this->indexFrom;
    
        if(!empty($to)){
            $to = rawurlencode ($to);
            $baseUrl .= "&t=".$to;  
        }
        if(!empty($weight)){
            $baseUrl .= "&w=".$weight;
        }
    
    $baseUrl .= $this->country;
    $baseUrl .= "&o=php";
    echo $baseUrl . "<br>";
    $ch = curl_init($baseUrl);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    $err = curl_error($ch);
    $errmsg = curl_errno($ch);
    
    $info['result'] = $result;
    $info['error'] = $err;
    $info['errormsg'] = $errmsg;
        if($info['http_code'] == 200){
            echo mb_detect_encoding($info['result']) . "</br>";
            echo "<pre>";
                print_r($info);
            echo "</pre>";
    
        }
    

    }

    And it's all kinds of good, the request's being made correctly (if the request to insert it into the browser, it's all right to open) but when the result is out through the crypt, it's gonna suck:

    введите сюда описание изображения

    Coding checked everywhere - utf-8. What's the problem?



  • I guessed. Read more carefully the documentation you yourself made on the question:

    Postcalc server response. RU always archived in gzip

    And a couple of suggestions are further described how to move on with this and even describe some possible robbers.

    // Добавляем распаковку:
    if ( substr($Response,0,3) == "\x1f\x8b\x08" ) $Response=gzinflate(substr($Response,10,-8));
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2