英文:
The requested route [/add_action] has not been mapped in Spark for Accept: [*/*]
问题
无论我做什么,我总是得到这个结果。在上面的GET请求中不会发生这种情况。
Java Spark:
package controllers;
import static spark.Spark.*;
import action.EmailReader;
import data.ActionReply;
import db.ActionsTable;
import spark.Request;
import spark.Response;
import spark.Route;
import utilities.JsonUtil;
import utilities.Tools;
public class ActionController {
public ActionController() {
get("/active_actions", (req, res) -> getActiveActions(res, req.queryParams("username")), JsonUtil.json());
put("/add_action/", (req, res) -> putActiveActions(res, req.queryParams("username"), req.queryParams("data")), JsonUtil.json());
}
public ActionReply getActiveActions(Response resp, String username) {
//Access-Control-Allow-Origin: http://siteA.com
resp.header("Access-Control-Allow-Origin", "*");
return new ActionReply("Success", true, "blahblahblah");
}
public ActionReply putActiveActions(Response resp, String username, String data) {
//Access-Control-Allow-Origin: http://siteA.com
resp.header("Access-Control-Allow-Origin", "*");
ActionsTable.addFlowToEngine(username, data);
return new ActionReply("Success", true, "Successful PUT.");
}
}
var edata = editor().getValue();
self.actions.push(edata);
$.ajax({
type: "PUT",
dataType: "json",
username: "dan_the_man",
data: edata,
url: "http://localhost:4567/add_action",
success: function(data){
console.log(data);
}
});
我还收到以下错误:
从origin 'null'阻止了对'http://dan_the_man@localhost:4567/add_action/'的XMLHttpRequest访问,因为CORS策略:预检请求的响应未通过访问控制检查:所请求的资源上没有'Access-Control-Allow-Origin'头。
我不知道为什么会出现这种情况,因为我已经设置了可以接受任何请求的头。
英文:
I get this no matter what I do. It does not happen on the GET right above it.
Java Spark:
package controllers;
import static spark.Spark.*;
import action.EmailReader;
import data.ActionReply;
import db.ActionsTable;
import spark.Request;
import spark.Response;
import spark.Route;
import utilities.JsonUtil;
import utilities.Tools;
public class ActionController {
public ActionController() {
get("/active_actions", (req, res) -> getActiveActions(res, req.queryParams("username")), JsonUtil.json());
put("/add_action/", (req, res) -> putActiveActions(res, req.queryParams("username"), req.queryParams("data")), JsonUtil.json());
}
public ActionReply getActiveActions(Response resp, String username) {
//Access-Control-Allow-Origin: http://siteA.com
resp.header("Access-Control-Allow-Origin", "*");
return new ActionReply("Success", true, "blahblahblah");
}
public ActionReply putActiveActions(Response resp, String username, String data) {
//Access-Control-Allow-Origin: http://siteA.com
resp.header("Access-Control-Allow-Origin", "*");
ActionsTable.addFlowToEngine(username, data);
return new ActionReply("Success", true, "Successful PUT.");
}
}
AJAX Request:
var edata = editor().getValue();
self.actions.push(edata);
$.ajax({
type: "PUT",
dataType: "json",
username: "dan_the_man",
data: edata,
url: "http://localhost:4567/add_action",
success: function(data){
console.log(data);
}
});
Error:
507936 [qtp1182316047-39] INFO spark.http.matching.MatcherFilter - The requested route [/add_action/] has not been mapped in Spark for Accept: [*/*]
I also get:
Access to XMLHttpRequest at 'http://dan_the_man@localhost:4567/add_action/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Which I don't know why its doing this since I am setting the header to accept anything.
答案1
得分: 0
我在我的服务器上遇到了相同的错误。这没有任何道理,因为我的客户端确实发送了一个“Accept”头部。但事实证明URL是错误的,客户端收到了404错误。
服务器没有记录正在请求一个无效的URL,而是在请求头部的“Accept”(接受)部分(映射到一个不存在的资源)时发出了投诉。
英文:
I ran into the same error on my server. It didn't make sense as my client WAS sending an Accept header. But it turned out the URL was wrong and the client was getting a 404.
The server was not logging that an invalid URL was being requested, but rather complaining of this mapping for the Accept header (to a non-existent resource).
专注分享java语言的经验与见解,让所有开发者获益!
评论