How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object

How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object

Article ID:290591
Last Review:July 13, 2004
Revision:1.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 "&" symbol to separate each name-value pair. For example:
input1=Hello&input2=World&idValue=12345
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 οnclick="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

REFERENCES

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

APPLIES TO
Microsoft XML Parser 3.0 Service Pack 3
Microsoft XML Parser 3.0 Service Pack 1
Microsoft XML 4.0
Keywords: 
kbhowto KB290591
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值