我正在尝试向我的Apache 2.2服务器发送“POST”请求(使用js)。 我是这样做的:
var req= new XMLHttpRequest();
req.open("GET", url + "?wsdl", async);
req.send(null);
var wsdl = req.responseXML;
var ns = (wsdl.documentElement.attributes["targetNamespace"] + "" == "undefined") ? wsdl.documentElement.attributes.getNamedItem("targetNamespace").nodeValue : wsdl.documentElement.attributes["targetNamespace"].value;
var sr = "correct soap request";
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", url, async);
var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
xmlHttp.setRequestHeader("SOAPAction", soapaction);
xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttp.send(sr);
最后在我得到的最后一行
无法加载资源:服务器响应状态为500 (内部服务器错误)XMLHttpRequest无法加载 https:// ...预检的响应 具有无效的HTTP状态代码500 Uncaught NetworkError:失败 在'XMLHttpRequest'上执行'send':无法加载 。的 'https:// ...'
这一次在我见过的apache的访问日志中
“GET ...?wsdl HTTP / 1.1”200 19708 “OPTIONS ... HTTP / 1.1”500 153
正如我发现这可能是因为我的请求不被认为是跨域请求的简单而浏览器首先进行预检。
我已经猜到我需要在我的apache配置中添加标题“Access-Control-Allow-Method”,但是在我的soap请求中添加'*'或'methodname',或者两者都没有效果。我的xmlHttp.send(sr)
UPD :我已经找到了一些信息,现在我的apache的httpd.conf在我的出版物块中看起来像这样:
<Directory "C:/apache/htdocs/point/">
AllowOverride All
Options All MultiViews
Order allow,deny
Allow from all
SetHandler 1c-application
ManagedApplicationDescriptor "C:/apache/htdocs/point/default.vrd"
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Method "POST, GET, OPTIONS"
Header set Access-Control-Allow-Headers "Overwrite, Destination, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, SOAPAction"
Header set Access-Control-Max-Age: 86400
</Directory>
但服务器仍在OPTIONS请求中返回500
UPD : 这是我的error.log:
[Fri Sep 23 11:20:24 2016] [error] [client ] Invalid method in request \xb9\x99%s\xfb
[Fri Sep 23 11:56:12 2016] [error] [client ] Invalid method in request \x7fk\xb7\xb0\xf3>\x1e\xee\xf1\xe9bY#}-*\xed%o\xf59\x02\xfa\x93\x85y8"\x07GZ\xca\x17\x81\x98\x11\xbcX;\xb6g\xe3\x19\xdb\xbb9\xd5\xa5\x8f\x17J\x93b\xbb
[Fri Sep 23 11:56:32 2016] [error] [client ] Invalid method in request \xe2\x18ze\x9c0\xb2
[Fri Sep 23 12:45:42 2016] [error] [client ] Invalid method in request 4\x99\x93E\x07\xf4\xa1\x94B\xb2\xf2\x1ai\xc9\xcd\xb0S\xb3\xc3\x8b\xac\xa8\x87F\x0e\xcaE\x9eB&(\xac\xee"%\x7fY\x88\xad\xf2\xb9\xcd45\xbf
[Fri Sep 23 13:20:23 2016] [error] [client ] Invalid method in request \x92\x80\x02_Dl4`\xc7\xb5R\x16\x91[\xb0\xeb&\xbb\x17\xb5l\x01M\xc5\xf1]\xec\xf1[\x8f\x14v\x07\x85,a
[Fri Sep 23 14:32:15 2016] [error] [client ] Invalid method in request \xbc\x9c\x91\xfeKI\xf3^\xa8\x07\xd7\x83\x1b\x9e
[Fri Sep 23 15:16:17 2016] [error] [client ] request failed: error reading the headers