Microsoft KB Archive/290591

= How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object =

Article ID: 290591

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q290591



SUMMARY
In some cases, you may want to send data to a port or server so that you can use the Form collection on the Request object in the page or listening application. To do this, you need to add headers to notify the receiver that the body contains data that can be accessed from the Form collection.



MORE INFORMATION
Requests that are being sent are based on two parts: the Header and the Body. The Header contains information about the Body so that the receiver knows what data is contained there.

Header Information
The Header information that needs to be set is the Content-Type. In this case, set this to the value of application/x-www-form-urlencoded.

Body Data
The Body contains the data that you want to send. The data takes the shape of name=value. For multiple values, you can use the &quot;&&quot; symbol to separate each name-value pair. For example:

input1=Hello&input2=World&idValue=12345

The receiver is able to pick the values &quot;Hello,&quot; &quot;World,&quot; and &quot;12345&quot; by using the names &quot;input1,&quot; &quot;input2,&quot; and &quot;idValue&quot; respectively.

Step-by-Step Instruction for ServerXMLHTTP Object
 Ensure that the server has MSXML 3.0 or later parser, that the Proxy Configuration Utility has been run, and that the settings have been configured. For more information, see the &quot;References&quot; section of this article.  Copy the following code into a new Active Server Pages (ASP) page called ServerHTTP.asp. Place the ASP page in the default Home directory. <%@ Language=vbScript%> <%   DataToSend = &quot;id=1&quot; dim xmlhttp set xmlhttp = server.Createobject(&quot;MSXML2.ServerXMLHTTP&quot;) xmlhttp.Open &quot;POST&quot;,&quot;http://localhost/Receiver.asp&quot;,false xmlhttp.setRequestHeader &quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot; xmlhttp.send DataToSend Response.ContentType = &quot;text/xml&quot; Response.Write xmlhttp.responsexml.xml Set xmlhttp = nothing %> NOTE: The two ASPs should be in different virtual folders due to threading issues.

If pooling is set to Low or Medium (this is the default for Microsoft Windows 2000), you should POST to an ASP in a different virtual folder. If the ASP is in the same virtual folder, the ASP stops responding (hangs). After you close the browser, that ASP and other ASPs continue to hang because the request stays queued even though you close the browser. You must restart IIS or restart the computer.

If you change the pooling to High, you can run the code to the remote ASP again because you are using a new thread.

  Copy the following code into a new ASP page called Receiver.asp. Place the ASP page in the default Home directory. <%@language=vbscript%> <%   value = Request.Form(&quot;id&quot;) Response.ContentType = &quot;text/xml&quot; response.write &quot;&quot; & value & &quot;&quot; %> When Posting, be sure that you use the name of the server, not Localhost, and that the URL that is being opened by the XMLHttp, should also contain the same server name.

 Ensure that the &quot;POST&quot; is pointing to the correct location. Click the Submit XMLHTTP button.</ol>

When you use just the XMLHTTP object from client-side script, the same header information and data format must be observed.

Step-by-Step Instruction for XMLHTTP Object
<ol>  Copy the following code into a new ASP page called ClientHTTP.asp. Place the ASP page in the default Home directory. <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>

</SCRIPT>

<INPUT type=&quot;button&quot; value=&quot;Submit XMLHTTP&quot; id=XMLHTTPButton name=XMLHTTPButton LANGUAGE=javascript onclick=&quot;return XMLHTTPButton_onclick&quot;> </li> Create the page from step 3 of the ServerXMLHTTP steps outlined previously.</li> Ensure that the &quot;POST&quot; is pointing to the correct location.</li> Load the ClientHTTP.asp in a browser</li></ol>

<div class="references_section">