Jquery ajax方法请求体为null,但poster工作正常

Jquery ajax method request body is null but postman is working normal

本文关键字:poster 工作 null 方法 ajax 请求 Jquery      更新时间:2023-09-26

我正在Mule ESB上配置一个服务,以提供我一直在使用jQuery和jQuery UI开发的接口。

Mule ESB包含一个http侦听器,该侦听器的方法是"POST",以获取请求体并对其进行评估,然后给出必要的响应。

这是我通过邮局发送的请求:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://localhost:8081/feed",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "cache-control": "no-cache",
  },
  "processData": false,
  "data": "{'r'n't'"vibs'": ['r'n't't'"TAS2002'"'r'n't],'r'n't'"language'": '"de-DE'"'r'n}"
}
$.ajax(settings).done(function (response) {
  console.log(response);
});

Mule ESB和web应用程序在不同的web主机(Mule的web服务器,web应用程序的节点http服务器)中运行,我知道这会影响跨域策略。。。但是我不知道我应该如何配置我的服务来处理这个请求。

Mule总是得到正文为null的请求,因为通常情况下,当我通过POSTMAN发送相同的请求时,poster会将请求的正文转移到[#message.epayload]对象中。

当我尝试使用jQueryajax或JavaScriptXHR等时,在调试器上,它显示请求负载为null。所以我无法评估请求主体。。。

有人能帮我解决这个问题吗?

顺便说一下,我使用Mule ESB 3.7.0作为服务器运行时,使用jQuery 1.10.2作为ajax。

如有任何帮助,我们将不胜感激,提前表示感谢!

尝试使用以下代码

var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://localhost:8081/feed",
    "method": "POST",
    "content-type": "application/json; charset=utf-8",
    "cache-control" : "no-cache",
    "processData": false,
    "data": "{'r'n't'"vibs'": ['r'n't't'"TAS2002'"'r'n't],'r'n't'"language'":      '"de-DE'"'r'n}"
}
$.ajax(settings).done(function (response) {
   console.log(response);
});

使用"headers": { "content-type": "application/json", "cache-control": "no-cache", },

我得到日志作为找不到请求的侦听器:(OPTIONS)/feed

希望这能有所帮助。