Welcome Guest, Not a member yet? Register   Sign In
viewing the output buffer
#1

(This post was last modified: 10-26-2018, 03:18 PM by richb201.)

this code is shoving my payload (aka $table) into the header:


   $this->output
       ->set_content_type('application/json')
       ->set_header("Access-Control-Allow-Origin", "*")
       ->set_output(json_encode($table));
}



Here is the Apache error log. 

[Fri Oct 26 18:22:07.162178 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] [client 69.124.178.164:57141] malformed header from script 'index.php': Bad header: {"0":["{choose}","IOS","Mac","
[Fri Oct 26 18:22:07.163669 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] [client 69.124.178.164:57141] AH01070: Error parsing script headers
[Fri Oct 26 18:22:07.163679 2018] [proxy_fcgi:error] [pid 2001:tid 139930806171392] (22)Invalid argument: [client 69.124.178.164:57141] AH01075: Error dispatching request to : 
[Fri Oct 26 18:22:33.796554 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] [client 69.124.178.164:57179] malformed header from script 'index.php': Bad header: {"0":["{choose}","IOS","Mac","
[Fri Oct 26 18:22:33.796627 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] [client 69.124.178.164:57179] AH01070: Error parsing script headers
[Fri Oct 26 18:22:33.796633 2018] [proxy_fcgi:error] [pid 2001:tid 139930797778688] (22)Invalid argument: [client 69.124.178.164:57179] AH01075: Error dispatching request to : 

Is there any way to view the header+output prior to it being put on the network wire? The header seems correct, its just in the wrong place.
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 10-27-2018, 04:42 AM by richb201.)

OK. After over a month of trial and error and banging my head against the wall i figured it out (or a workaround). I now use:
           header('Content-type: application/json');
           header("Access-Control-Allow-Origin: *");
           echo ($json);

instead of

  $this->output
      ->set_content_type('application/json')
      ->set_header("Access-Control-Allow-Origin", "*")
      ->set_output(json_encode($table));
proof that an old dog can learn new tricks
Reply
#3

Do you have an exit; or die; after $this->output?

If that's the case you need to add _display() after. If that causes the malformed headers to be rendered.
https://www.codeigniter.com/userguide3/l...::_display
Reply




Theme © iAndrew 2016 - Forum software by © MyBB