Apologies if this is not directed to the correct mailing list (please
let me know where better if that's the case), but here's my question :
I'm trying to post a hunk of XML via XMLHttpRequest using the
following javascript:
var r = new XMLHttpRequest();
var targeturl = "http://.....";
var string_of_xml_data = "<?xml version=\"1.0\"?>\n<foo>bar</foo>";
...
r.open("POST",targeturl,true);
r.setRequestHeader("Content-Type", "text/xml");
r.send(string_of_xml_data);
What actually goes out on the wire is an HTTP OPTIONS call to the
targeturl. If I drop the setRequestHeader line, then what actually
goes out on the wire is an HTTP POST (content type 'text/plain'). The
problem is, the targeturl will only accept 'text/xml', so I'm trying
to figure out how to make this go.
It took my a long time to figure out why the response was always zero
bytes with the text/xml content-type, but that's because the HTTP
method is going out as OPTIONS; which the target_url server replies
too with a 200 response and a bunch of headers.
Thanks in advance for any help-
daniel
Daniel,
Have a look at the following link :
https://developer.mozilla.org/en/HTTP_access_control
It descibes FF 3.5's support for W3C's Access Control for Cross-Site
Requests.
A cross-domain HTTP POST with a Content-Type other than application/x-
www-form-urlencoded, multipart/form-data, or text/plain results in a
"preflighted" request which first sends an HTTP OPTIONS request header
to the resource on the other domain, in order to determine whether the
actual request is safe to send.
Kevin H.