gpt4 book ai didi

java - 我可以在 URL 路径中使用顶级域名吗?

转载 作者:可可西里 更新时间:2023-11-01 16:56:25 25 4
gpt4 key购买 nike

我有一个使用 Spring 3.2.2 的应用程序。我在 Tomcat 上运行它。

在应用程序中,我有一个返回 JSON 的 Controller 。

如果 Controller 请求映射包含字符串“.com”、“.org”、“.talk”,我会收到 HTTP 错误 406

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

示例:

这很好用:

@RequestMapping(method = RequestMethod.GET, value = "/test.test")
public @ResponseBody Map<String, String> test() {
Map<String, String> stringMap = new HashMap<String, String>();
stringMap.put("test", "test");
return stringMap;
}

这会导致 HTTP 错误 406:

@RequestMapping(method = RequestMethod.GET, value = "/test.talk")
public @ResponseBody Map<String, String> test() {
Map<String, String> stringMap = new HashMap<String, String>();
stringMap.put("test", "test");
return stringMap;
}

我尝试过的所有域名都没有重现该问题。例如“.net”工作正常。

最佳答案

我遇到了与上述相同的问题。我的应用程序在 Jetty 中工作,但在 Tomcat 中不工作。但是,在我的例子中,调用从未到达 Spring Controller 。

因此,如果您也是这种情况,则可能是 Tomcat 配置问题。 Tomcat 在文件 web.xml 中有 mime 映射。删除不需要的 comorg 等映射,406 应该消失。

从文件 apache-tomcat-7.x/conf/web.xml 中删除以下内容:

<mime-mapping>
<extension>org</extension>
<mime-type>application/vnd.lotus-organizer</mime-type>
</mime-mapping>

<mime-mapping>
<extension>com</extension>
<mime-type>application/x-msdownload</mime-type>
</mime-mapping>.

关于java - 我可以在 URL 路径中使用顶级域名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18956226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com