logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Status Code 406 using headers with [Accept:application/json]
Author
passingsword



Joined: 27 Jul 2023
Posts: 1

PostPosted: Thu 27 Jul '23 17:36    Post subject: Status Code 406 using headers with [Accept:application/json] Reply with quote

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.


Also, If i request to a.php instead of a, it works well.


I wonder the config somewhere is wrong, have tried everything I googled, but nothing works.



errorLog:
Code:
AH00690: no acceptable variant




Request Headers:
Code:
GET a HTTP/1.1
Host: 127.0.0.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:
Code:
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




a.php:
Code:
<?php
header('Content-type: application/json');
$result[data] = 'yes';
echo json_encode($result);
?>




406 Page:
Code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource a.php could not be found on this server.</p>
Available variants:
<ul>
<li><a href="a.php">a.php</a> , type application/x-httpd-php</li>
</ul>
</body></html>
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Fri 28 Jul '23 3:12    Post subject: Reply with quote

Code:
<br />
<b>Fatal error</b>:  Uncaught Error: Undefined constant &quot;data&quot; in D:\Qampp\htdocs\test.php:3
Stack trace:
#0 {main}
  thrown in <b>D:\Qampp\htdocs\test.php</b> on line <b>3</b><br />
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Fri 28 Jul '23 3:13    Post subject: Reply with quote

Code:
<?php
header('Content-type: application/json');
// $result = array(); 
$result['data'] = 'yes';
echo json_encode($result);
?>
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7316
Location: Germany, Next to Hamburg

PostPosted: Fri 28 Jul '23 8:28    Post subject: Reply with quote

What PHP version do you use? I tested this code, and it works as expected.
Back to top


Reply to topic   Topic: Status Code 406 using headers with [Accept:application/json] View previous topic :: View next topic
Post new topic   Forum Index -> Apache