阿帕奇406不接受指定接受时:头 [英] Apache 406 Not Acceptable when specifying Accept: header

查看:156
本文介绍了阿帕奇406不接受指定接受时:头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找到一个解决方案,但自己与其他406问题的解决方案并没有帮助我。

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

我已经启用了PHP和我的Mac上的Apache Web服务器。我发现,如果我通过一个请求(POST或GET)与接受:头,那么它失败了406错误:

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>

不过,如果我排除了接受:应用/ JSON的要求执行没有错误,

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

我尝试添加此测试/ tester.var(在相同的目录作为试验/ tester.php):

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

URI: tester

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

我的目的是引导Apache来处理与要求:通过执行tester.php接受应用程序/ JSON。但它并没有帮助我(我还加'的AddHandler型地图.VAR'下'IfModule mime_module我的httpd.conf文件里面并重新启动服务器)。

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的不会出现配置,但我增加了以下的.htaccess到我的测试/目录反正:

'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.

任何想法?

推荐答案

我终于想出了一个修复!正如我怀疑,* * mod_security的事不关己与我的问题。

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

下面是我给的 /etc/apache2/httpd.conf 的所做的更改:

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


  1. 已启用类型通过取消注释的AddHandler型地图变种行中的映射
    在IfModule mime_module部分。

  2. 增加了以下两行的IfModule mime_module部分:

  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


在我的PHP源代码目录,我创建了一个的 tester.var 的在同一目录中的 tester.php 的与内容:

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.

这篇关于阿帕奇406不接受指定接受时:头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆