What is wrong in my PHP Function

I was trying to generate QRCode using Google Map API and PHP. When I executed it in a browser it’s giving me a qrcode image. But I implemented same code as an API…It’s just printing image url.

Below is my code

1)This is API:

      $app->post('/genQR',function () use($app){
     
      $luname = $app->request->post('luname');
      $prof   = $app->request->post('prof');

      $con = new DbHandler();
      $con->genQR($luname,$prof);
    });

2)Function part

        public function genQR($luname,$prof)
        {
          $ip = $luname ." ". $prof;
          $ex2 = new QRGenerator($ip,150);
         header ("content-type:image/png");
         echo "<img src=".$ex2->generate().">";
        }

When i tested in postman it’s simply giving op in below manner

    <img src=https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=pradeep+1&choe=UTF-8&chld=L|4>

What can be the error…??

What else than a text/string did you expect to get from your API? That’s the same you get from any other webpage. The behaviour to display the contents depends on the client you use. Postman is not an HTML Browser, it will not 1. get the contents, 2. parse them, 3. download linked ressources, 4. display them in a single graphical interface. This is the same result you will get when looking at the source code of your own webpage without API. Maybe you get some graphical interpretation in the “preview” tab. But i don’t see any sense in that - if you just want to output and display HTML, use the regular website, an API is inappropriate for this task.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.