【发布时间】:2017-02-11 23:11:21
【问题描述】:
我正在调用 API 以返回带有所有需要的对象(注释)的 JSON:
$( document ).ready(function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var response = xhr.responseText;
//do stuff with response
}
xhr.open('GET', 'http://mydomain:8080/notes/all', true);
xhr.send(null);
});
HTTP 请求:
@RequestMapping(value = {"/all"}, method = RequestMethod.GET, produces = "application/json")
public @ResponseBody List<Note> getAllNotes() {
return noteService.getAllNotes();
}
当我在 Mac 上本地运行时,一切正常。我的 Response 标头有 Content-Type: application/java,并且 Request 接受它。
但是,当我将 .war 上传到 Ubuntu 16.04 服务器时,请求标头的 Content-Type 更改为 txt/html,然后我得到了
404 页面未找到
。
我在两台机器上都使用tomcat8.5.5。
如何指定/更改请求标头内容类型?
标题图片: 远程运行 和本地
【问题讨论】:
-
内容类型是 text/html 因为返回了错误页面 404,它是一个 html 页面并且是有效的内容类型。您需要解决的是为什么在 Ubuntu 上返回 404。参考您的 Javascript 代码,该代码是否来自同一个应用程序?
标签: javascript spring ubuntu tomcat server