Microsoft KB Archive/282102

= PRB: ServerXMLHTTP Object Adds Content-Type Header with XML Data =

Article ID: 282102

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft XML Core Services 4.0

-



This article was previously published under Q282102



SYMPTOMS
When posting XML data to a Web server by passing a DOMDocument object to the send method of a ServerXMLHTTP object, a content-type header of &quot;text/xml&quot; is automatically added. If you set the request header before sending XML data, the content-type header sent to the Web server is &quot;Text/xml, text/xml&quot; instead of &quot;Text/xml,&quot; which may cause problems.



CAUSE
The following is an example of Microsoft JScript code that could cause the problem to occur: var xmlhttp = new ActiveXObject(&quot;MSXML2.ServerXMLHTTP&quot;); var doc = new ActiveXObject(&quot;MSXML2.DOMDocument&quot;); xmlhttp.open(&quot;POST&quot;, &quot;http://localhost/acceptpost.asp&quot;, false);

//set the content-type as Text/xml xmlhttp.setRequestHeader(&quot;Content-Type&quot;, &quot;Text/xml&quot;); doc.async=false; doc.loadXML(&quot;myStock&quot;); xmlhttp.send(doc); The ServerXMLHTTP object first inspects the data and, when it finds that the data is XML, it adds the &quot;text/xml&quot; content-type header.

If the data is not XML, this content-type header is not added. The following code is an example of this scenario: var xmlhttp = new ActiveXObject(&quot;MSXML2.ServerXMLHTTP&quot;); xmlhttp.open(&quot;POST&quot;, &quot;http://localhost/acceptpost.asp&quot;, false); xmlhttp.send(&quot;myStock&quot;);



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
There are two possible workarounds to this problem:  Do not call setRequestHeader for XML data because the ServerXMLHTTP sets the content-type header for you in this case.

  Pass the value of the xml property of the DOMDocument to the send method of ServerXMLHTTP instead of passing the DOMDocument itself. For example, modify the last line of the example in the first code snippet in the &quot;Cause&quot; section to be: xmlhttp.send(doc.xml); </ul>

Keywords: kbbug kbprb kbmsxmlnosweep KB282102

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.