Why we use
header('Content-Type: application/json');
Before
echo json_encode($data)
in the web services in php
If I will not use header('Content-Type: application/json');
what is its disadvantage?
Help will be appreciated
When you are defining the Content-Type in headers of the any response, tell the client about which type of content they are receiving in response. When we are sending the JSON encode string in the response we should always set Content-Type:application/json in headers.
Default "Content-Type:text/html" is set in response PHP headers.
You should always set Content-Type: application/json if you are sending json. Headers are used to tell the other side what kind of data you are sending and is a best practice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.