Status Code 406 using headers with [Accept: application/json]
Posted by: passingsword (103.172.41.---)
Date: July 26, 2023 05:30PM

When I send a GET request to a.php using headers with [Accept: application/json], my server gives me 406.
If I remove [Accept: application/json] from headers, everything works well and gives me 200.
I have tried everything i googled, but nothing works.
How can the server accept requests with [Accept: application/json] and dealing it with php?

Request Headers:
GET a.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: application/json
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Sec-Fetch-User: ?1
Pragma: no-cache
Cache-Control: no-cache

Response Headers:
HTTP/1.1 406 Not Acceptable
Date: Wed, 26 Jul 2023 15:28:33 GMT
Server: Apache
Alternates: {"a.php" 1 {type application/x-httpd-php} {length 104}}
Vary: negotiate
TCN: list
Content-Length: 353
Keep-Alive: timeout=60
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

header('Content-type: application/json');
$result[data] = 'yes';
echo json_encode($result);

406 Page:
<title>406 Not Acceptable</title>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource a.php could not be found on this server.</p>
Available variants:
<li><a href="a.php">a.php</a> , type application/x-httpd-php</li>

Edited 1 time(s). Last edit at 07/26/2023 05:36PM by passingsword.

Options: ReplyQuote
Re: Status Code 406 using headers with [Accept: application/json]
Posted by: Otomatic (Moderator)
Date: July 27, 2023 08:49AM

Perhaps the loading of an Apache module is missing.
This is a question for Apache, possibly in the ApacheLounge forums.

Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote

Sorry, only registered users may post in this forum.