0

I'm trying to send a "POST" request (using js) to my Apache 2.2 server. I do it like this:

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);

finally on the last line I get

Failed to load resource: the server responded with a status of 500 (Internal server error) XMLHttpRequest cannot load https://... Response for preflight has invalid HTTP status code 500 Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://...'.

this time in the access log of apache I've seen

"GET ...?wsdl HTTP/1.1" 200 19708 "OPTIONS ... HTTP/1.1" 500 153

As i've found this may be because of my request is not recognized as simple for cross-domain requests and browser first makes a preflight. I've guessed that I need to add header "Access-Control-Allow-Method" to my apache config but adding it with '*' or 'methodname' that is in my soap request, or both gives no effect. I still have the same errors on my xmlHttp.send(sr)

UPD: I've found some information and now in my apache's httpd.conf in my publication's block looks like this:

 <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>

but server still returns 500 on OPTIONS request

UPD: here is my 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
Nikitin Mikhail
  • 2,983
  • 9
  • 42
  • 67
  • it's not "interpreting". That's how cross-domain ajax w3orks. You're demanding a "foreign" url, so the browser issues an OPTIONS request to that foreign server to see if it'll allow cross-domain ajax. You have to configure the server you're HITTING with that cross-domain request to allow it, not your own server. YOu can't grant yourself cross-domain rights. That'd be like showing the bank a scribbled note saying "I'm allowed to have all the money in the vault". – Marc B Sep 22 '16 at 21:33
  • @MarcB maybe my wording is not as correct as it should be, but I'm hitting MY own server where my webapp is that accepts all the methods via SoapUI but I have the problem descrybed with js. So asking why i of course want to know the exact reason of my problems (but for myself) and how should I configure my server to deal with it... – Nikitin Mikhail Sep 22 '16 at 21:41
  • well, general rule: if you get a 500, you go look at the server's error log for details. it could be anything from your own app crashing, or a typo in a .htaccess. until you know why, anything else is random poking in the dark. – Marc B Sep 23 '16 at 13:48
  • @MarcB added information from error.log but can't understand what could it mean – Nikitin Mikhail Sep 23 '16 at 14:28
  • @MarcB I actually see the error "error reading headers" But as far as I see there are no more headers set to xmlHttp but "SOAPAction" and "Content-Type" – Nikitin Mikhail Dec 23 '16 at 14:25

0 Answers0