2016-09-21 4 views
-1

У меня есть одна форма, и я создал один URL-адрес для извлечения данных. Он правильно извлекает данные, но когда я нажимаю URL-адрес, он показывает мне {"error": "null"}. Как получить представленную стоимость? Я не могу отображать веб-службы. Я пытаюсь создать веб-сервис. После подачи формы, когда я пытаюсь ударить URL со значениямиPHP url не удалось получить отправленные данные

http://www.apnapaisa.com/ajaxv2/getCompareResults.html?rateType=Both&occupation=Salaried&offeringTypeId=31&city=79&loanAmt=500000&q=&age=27 

это дает мне { "ошибка": "нулевой"} ошибки

<?php 
    if($_POST["occupation"] == '1'){ 
     $occupation = 'Salaried'; 
    } 
    else{ 
     $occupation = 'Self+Employed'; 
    } 

    $url = 'http://www.apnapaisa.com/ajaxv2/getCompareResults.html?productId='.$_POST["product_id"].'&rateType=Floating&occupation='.$occupation.'&monthlyIncome='.$_POST["dincome"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&monthlyIncomeSingle='.$_POST["dincome"].'&loanAmt='.$_POST["loan"].'&q='.$_POST["q"].'&age='.$_POST["age"].'&tenure='.$_POST["tenure"]; 
    echo $url; 
    // Initiate curl 
    $ch = curl_init(); 
    // Disable SSL verification 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    // Will return the response, if false it print the response 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    // Set the url 
    curl_setopt($ch, CURLOPT_URL,$url); 
    // Execute 
    $result=curl_exec($ch); 
    // Closing 
    curl_close($ch); 
    $json = json_decode($result, true); 

    //print_r($json); 
    //echo $json['resultList']['interestRateMin']; 
    $json_array = $json['resultList']; 

    //print_r($json_array); 

    ?> 

     <?php 
      if (is_array($value)) { 
     foreach ($json['resultList'] as $key=>$value) { 
      if($json["resultList"][$key]["interestRateMin"] == $json["resultList"][$key]["interestRateMax"]){ 
       $interest = $json["resultList"][$key]["interestRateMin"]; 
      } 
      else{ 
       $interest = $json["resultList"][$key]["interestRateMin"].' - '.$json["resultList"][$key]["interestRateMax"]; 
      } 
       echo ' 
        <div class="bank-rates"> 
     <ul> 
    <li><div class="innr-spl" style="padding: 5px 0;"><span style="display:block;"><img src="'.$json["resultList"][$key]["imageUrl"].'"></span></div></li> 
    <li><div class="innr-spl2">'.$json["resultList"][$key]["interestRateMin"].'%'.'</div></li> 
    <li><div class="innr-spl2">60</div> </li> 
    <li class="hide"><div class="innr-spl3 view-detail1" id="'.$key.'"><i class="fa fa-chevron-circle-down" aria-hidden="true"></i>View Datails</div> </li> 
    <li><div class="apply-now innr-spl"><a href="#" type="button" role="button" target="_blank" class="btn-apply">Apply Now</a></div></li> 
     </ul> 
     <div style="clear:both"></div> 
     <div id="ban_'.$key.'"> 
     <ul class="details" id="details1"> 
     <li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Maximum Loan Amount : '.$json["resultList"][$key]["loanAmt"].'</li> 
     <li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Max Tenure (In Years) : '.$json["resultList"][$key]["tenure"].'</li> 
     <li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Interest Rate Type : '.$json["resultList"][$key]["rateType"].'</li> 

     </ul> 
     </div> 
    </div> 


       '; 
       $i++; 
     } 
} 
    ?> 
+0

Бррр. Пожалуйста, прочитайте о urlescaping или при создании URL-адресов таким образом. – arkascha

+0

Является ли метод api 'get' или' post'? –

+0

Я использовал метод post – user5397448

ответ

0
// $postData = xxx; //add your data 
    foreach($_POST as $k => $v) 
    { 
     $postData .= $k . '='.$v.'&'; 
    } 
    $postData = rtrim($postData, '&'); 

$url ="http://www.apnapaisa.com/ajaxv2/getCompareResults.html" 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); // Includes the header in the output 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$postData); 
$output=curl_exec($ch); 
+0

как я могу добавить свои данные, которые хочу захватить? – user5397448

+0

$ postData = rateType = '. $ _ POST ["rateType"].' & Occupation = '. $ _ POST ["оккупация"].' & OfferTypeId = '. $ _ POST ["offerIDID"].' & City = '. $ _ POST [ "город"] '& loanAmt =' $ _ POST [ "loanAmt"] '& д =' $ _ POST [ "ц"] и возраст = '$ _ POST [ "возраст"]......; – user5397448

+0

вот как я должен был добавить? – user5397448

Смежные вопросы