2017-03-10 23:20
浏览 69


I need to display the JSON response received from an API call. But due to some issues it doesn't display the response. Server/IP settings, API status are everything OK at API provider's end. So now, I couldn't figure out the issue.

I'm doing the PHP part in the following way:



    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);
    $json = json_decode($output, true);

    $resCode = $json['resCode'];
    $resText = $json['resText'];

    $rows = $json['data']['ROWS'];

    if (count($rows) > 0) {

                        echo "<table border='1' width='50%' align='center'><thead><tr>
                        <th>Validity (days)</th>
                        foreach($rows as $key => $value)
                            echo " <tr><td>" .$value["column1"] . "</td> <td>" .$value["column2"] . "</td> <td>" .$value["column3"] . "</td> <td>" .$value["column4"] . "</td> </tr>";
                        echo "</tbody></table><br/>";
                echo "Not available <br/> Try again!";

JSON Response from API


        "ROWS": [



Getting Output:

Not available  
Try again!

Expecting Output in HTML

<table border="1" width="50%" align="center">
  <th>Column 1</th>
  <th>Column 2</th>
  <th>Column 3</th>
  <th>Column 4</th>

Any help will be appreciated! Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dor2p0520 2017-03-13 11:20

    I used curl_error($ch) to know if there's any error with curl. And it let me know that I'm facing the issue because of SSL validation issue with the API URL.

    So, I removed the s from https in the API URL. And it worked!

    I know its a security compromise! But the referrer url is using http, so I need to remove the SSL validation from api url too.

    点赞 打赏 评论

相关推荐 更多相似问题