360
Chapter 6
Hey, I bet it’s just as easy to send an XML
request as it is to receive an XML response.
It turns out that you’ve got to do a good bit of
work to send XML... in fact, quite a bit more
work than it took to receive XML from the
server. Most of the time, the effort you’ll have
to put into sending XML just isn’t worth it.
First, you’ll need to send the XML in a POST
request...
Well, there’s a little more to it...
Sure, that makes sense. Because XML can
get pretty long, and there’s that maximum
URL length on GET requests, right?
It doesn’t take a lot of data before an XML
document gets pretty long. You’ll denitely
need to use a POST request. Additionally,
you’ll need to let the server know that you’re
sending it XML, not name/value pairs.
That’s right.
Even the short XML
response from the
Boards server took up
almost 200 characters!
That’s easy, too. I bet we can use a different
Content-Type request header, right?
You can use the setRequestHeader()
method on your request object to tell the
server that you’re sending it XML, like this:
You’ve really got this stuff down!
request.setRequestHeader(“Content-Type”, “text/xml”);
This tells the server that the content type of the
incoming message is XML, in text format.
sending xml requests