douwu7168 2013-03-21 03:11
浏览 143
已采纳

指定Accept:标头时,Apache 406不可接受

I've tried to find a solution for this myself but solutions to other 406 problems haven't helped me.

I have enabled PHP and the Apache web server on my Mac. I have found that if I pass a request (POST or GET) with the Accept: header set, then it fails with a 406 error:

$ curl -X GET -H "Accept: application/json" http://localhost/test/tester
<!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 /test/tester could not be found on this server.</p>
Available variants:
<ul>
<li><a href="tester.php">tester.php</a> , type application/x-httpd-php</li>
</ul>
</body></html>

However, if I exclude the "Accept: application/json" the request executes without error.

I tried adding this test/tester.var (in the same dir as test/tester.php):

URI: tester

Content-type: application/json
URI: tester.php

My intention was to direct Apache to handle request with "Accept: application/json" by executing tester.php. But it hasn't helped me (I also added 'AddHandler type-map .var' under 'IfModule mime_module' inside my httpd.conf file and restarted the server).

'mod_security' doesn't appear to be configured, but I added the following .htaccess to my test/ directory anyways:

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

These are solutions that I found on the net by none have worked for me.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duankezong4064 2013-09-23 03:29
    关注

    I finally figured out a fix! As I suspected, *mod_security* had nothing to do with my problem.

    Here are the changes that I made to /etc/apache2/httpd.conf:

    1. Enabled type maps in by uncommenting "AddHandler type-map var" line in the "IfModule mime_module" section.
    2. Added the following two lines to the "IfModule mime_module" section:

      AddType application/x-httpd-php .php
      MultiviewsMatch Handlers Filters
      

    In my PHP source directory, I created a tester.var in the same directory as tester.php with the contents:

        Content-type: application/json
        URI: tester.php
    

    It's all good now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分