Response content-type text/html while expected application/json

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Response content-type text/html while expected application/json



I have the same application on two different servers. On one server there is everything OK the application is loaded correctly. On the second server the application can't load. The error message is Unexpected token < in JSON at position 0. When I open developer tools in a browser I see that response content type header on the second server is text/html while on the first server is application/json what it should be.
On both servers in IIS MIME Types is .json application/json.
What else could block the corect content type on the second server?





Both servers are IIS? Same server version? Same code deployed?
– notionquest
Mar 15 '17 at 16:27





Yes they are exactly the same
– soldous
Mar 16 '17 at 6:43




2 Answers
2



Here is one of possible answers:
In our case it turned out that the cause was IIS setting, actually Application Pool setting. Instead of using Integrated, we had it switched to Classic.
When using Classic Application Pool in IIS, all JSON media type responses were converted automatically http/text.



Switching it back to Integrated Application Pool solved the issue.
Hope it helps somebody.
Radek



Not sure if it's caused by the same issue you're facing, but on our server we had to force the header to have it's content type as json to deal with something similar.



Thats the line of code we added:


header('Content-type:application/json;charset=utf-8');



.


public function renderError($err)
header('Content-type:application/json;charset=utf-8');
echo json_encode(array(
'success' => false,
'err' => $err
));



Hope that can help somehow. :)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard