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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)