You are currently offline, waiting for your internet to reconnect

How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object

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 "&" symbol to separate each name-value pair.For example:
The receiver is able to pick the values "Hello," "World," and "12345" by using the names "input1," "input2," and "idValue" respectively.

Step-by-Step Instruction for ServerXMLHTTP Object

  1. 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 "References" section of this article.
  2. 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 = "id=1"	dim xmlhttp 	set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")	xmlhttp.Open "POST","http://localhost/Receiver.asp",false	xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"	xmlhttp.send DataToSend	Response.ContentType = "text/xml"	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.

  3. 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("id")	Response.ContentType = "text/xml"	response.write "<ReturnValue>" & value & "</ReturnValue>"%>					
    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.

  4. Ensure that the "POST" is pointing to the correct location.
  5. Click the Submit XMLHTTP button.
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

  1. 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><!--function XMLHTTPButton_onclick() {	var DataToSend = "id=1";	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	xmlhttp.Open("POST","http://<%=Request.ServerVariables("Server_Name")%>/Receiver.asp",false);	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	xmlhttp.send(DataToSend);	alert(xmlhttp.responseXML.xml);}//--></SCRIPT><INPUT type="button" value="Submit XMLHTTP" id=XMLHTTPButton name=XMLHTTPButton LANGUAGE=javascript onclick="return XMLHTTPButton_onclick()">					
  2. Create the page from step 3 of the ServerXMLHTTP steps outlined previously.
  3. Ensure that the "POST" is pointing to the correct location.
  4. Load the ClientHTTP.asp in a browser
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
289481 How To Proxy Configuration Utility Must Be Run for ServerXMLHTTP to Work

Article ID: 290591 - Last Review: 06/22/2014 11:04:00 - Revision: 2.0

  • kbhowto KB290591