Wrox Programmer Forums
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 11th, 2003, 03:58 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Posting XML to an ASP page using XMLHTTP

Im basically using a VB application to post XML to an asp page. I've created the code that sends the post ... and so far I think it's working fine. It is as follows:
VBCode:
Quote:
quote:Dim oHttp As New XMLHTTP

oHttp.Open "POST", "http://www.myurl.com/blah.asp", False

oHttp.setRequestHeader "Content-Type", "text/xml"
oHttp.send "<xml text>contents of the file</xml>"
Now that is executing and I'm getting back the responseText just fine, the only problem is I can't figure out how to extract the xml in the asp page. I can access all the header information via Request.ServerVariables ... and if I check Request.ServerVariables("CONTENT_LENGTH") it tells me there is 1200+ characters of inromation in the post, I just can't figure out how to access it?

How do I pull out my xml data so that I can save it as an xml file on the server? Do i need to load it into a DOM object? can I just reference it directly?

Okay, this is the code i'm trying to use to extract the XML from the post and save it as an xml file:
Quote:
quote:dim xmldoc
set xmldoc = Server.CreateObject("Msxml2.DOMDocument")
xmldoc.async = false
xmldoc.resolveExternals = false
xmldoc.load(Request)
xmldoc.save(Server.MapPath("sample.xml"))
I don't know if it matters but my text xml is as follows:
Quote:
quote:<AuthorsList>
    <Author au_id="0001" au_name="Kelly"/>
    <Author au_id="0002" au_name="Derek"/>
    <Author au_id="0003" au_name="Don"/>
<AuthorsList>
My result? well let's just say I have a very empty sample.xml file on the server that I want to be filled with the xml I'm sending!!!

Help...
 
Old September 12th, 2003, 09:11 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think the problem you are having is that you are not specifying what fields the posted data belongs to. I haven't worked with this object, but it seems there is something missing.

I just found something that might be useful...
http://www.eggheadcafe.com/articles/20010510.asp

Maybe this will work...

oHttp.send "xml=" & Server.URLEncode("<xml text>contents of the file</xml>")

This will specify your xml "stream" as the form field "xml"
Then on your receiving asp page you just need to do this:

xmldoc.load(Request("xml"))

Also, if you wanted to add additional fields to your post data, you need to separate with a "&" just like you do in a regular URL.

HTH,
Peter
 
Old September 13th, 2003, 02:31 AM
Authorized User
 
Join Date: Sep 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi planoie.
   xmldoc.load(Request("xml")) does not work.
Also cannot use Server.URLEncode in vb.net. Any equivalent of this ?

If you don't mind can I add you MSN address in my buddy list ?

Thanks for all your help.
 
Old September 15th, 2003, 09:23 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Sorry, I missed that you are generating this request from VB. Try this...
System.Web.HttpUtility.UrlEncode()
When you are in a web application, this method is immediately visible because of all the default references and imports.

I'm not sure what to tell you about the XMLdoc.load problem. You could be more explicit and write xmldoc.load(Request.Form("xml"))

The other thing you could do is write a simple loop that just goes thru all the form elements to make sure everything's getting posted correctly:

Dim sKey
For Each sKey In Request.Form
    Response.Write(sKey & ":" & Request.Form(sKey) & "<br>")
Next

Peter
 
Old September 15th, 2003, 03:14 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Unfortunately you can't use Server.URLEncode or System.Web.HttpUtility.UrlEncode() in VB 6 ;) not using VB.NET here .. yet.

Any suggestions how to encode the HTML in VB6?

 
Old April 24th, 2014, 05:54 AM
Registered User
 
Join Date: Apr 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Planoi,

I am doing the above process suggested by you in my classic asp code. But i am not getting correct results. Could you please help me out here. My code is

Send Request.asp
Dim xmlString, httpRequest, postResponse,msXMLDocu,NewXmlDoc

xmlString = "<?xml version=""1.0"" encoding=""UTF-8""?><School><Class>10</Class></School>"

Set msXMLDocu = Server.CreateObject("Msxml2.DOMDocument.6.0")
'msXMLDocu.ValidateOnParse = True
msXMLDocu.async = False
msXMLDocu.LoadXML(xmlString)

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
httpRequest.Open "POST", "http://localhost/TestVBScript/RecieveRequest.asp", True
httpRequest.SetRequestHeader "Content-Type", "text/xml"
httpRequest.Send Server.URLEncode(msXMLDocu.xml)

If Err.Number <> 0 Then
Response.Write("Your web site does not appear to be up right now. Please try again later.")
Err.Clear
Else
Response.write("data successfully posted<br />")
End if

Now i want to receive the request on ReceiveRequest.asp page and i have written below code there
Dim xmlDoc
set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async="True"
xmlDoc.load(Request)

Also i am using the worker process in visual studio to debug the code. When i do post from one page to other, is there any way my debugger will shift to that location.

Any help will be appreciated, Thanks in advance.

Salil Gupta
+91-9718063565

Last edited by salilg; April 24th, 2014 at 06:04 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Posting XML data via XMLHTTP steelrose XML 1 November 15th, 2007 05:19 PM
PROBLEMS! Posting Form Fields with XMLHTTP kevorkian Classic ASP XML 2 December 7th, 2006 03:43 PM
Posting String Array From one page to another page Samatha ASP.NET 1.0 and 1.1 Professional 1 December 6th, 2006 03:54 AM
post xml using xmlhttp in vb.net datakix VB.NET 3 December 21st, 2004 01:31 PM
XML Post using microsoft.XMLHTTP csmajor231 XML 0 April 5th, 2004 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.