jd311
asked on
SENDING XML FILE TO A SERVER**URGENT**
Hey,
My project is to create a banner on our companies website which actually allows our
customers to check the availability of a domain name of their choice.The domain name that they enter has to be embedded in an xml file Our hosting services have given us an API which actually defines the DTD's to be used ,the url of their server and the specific port that they want us send the xml file too.The reply that whether the domain name is available or not will also be sent to us as an xml file(the DTD of which is specified to) which I need to then parse and display the result to our user as to whether the domain name that they have entered is available or not.
I was able to generate the xml file dynamically based on the users input.The only problem is that I am unable to send it to the target server as desired.
Here is the header and an example of a xml file that the www.networksolutions.com(one with whom we register domains) people want us to use :
The following sample HTTP request illustrates the actual content that a client sends to the
Network Solutions server to accomplish a task (in this case a name availability request). This
example includes the header information section followed by the respective content information
section.
POST /invoke/Network Solutions.transactionproxy .Inbound/X MLAvailabl eProxy HTTP/1.0
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: text/xml
Content-length: 265
<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
<RequestHeader>
<VERSION_3_4></VERSION_3_4 >
<Authentication>
<PartnerID>123</PartnerID>
<PartnerPassword>partner</ PartnerPas sword>
</Authentication>
<Comments></Comments>
</RequestHeader>
<Body>
<VerifyDomainName>example. com</Verif yDomainNam e>
</Body>
</AvailableRequest>
I tried to use MSXML core services but was unsuccesful.
************************** ********** ********** ********** ********** *
************Here is the code that I am using which actually builds xml file dynamically***
************************** ********** ********** ********** ********** *
<%@ LANGUAGE="VBScript" %>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
Sub SetValues()
Dim domain
Dim ext
domain=txtDomain
ext=cmbExt
End Sub
</SCRIPT>
<HTML>
<HEAD>
<title>New Page 1</title>
</script>
</head>
<body>
<%
Dim test
If (Request.Form.Item("txtDom ain") = "") then
//domain = Request.Form ("txtDomain")
//ext = Request.Form ("cmbExt")
//Response.Write (domain & "." & ext & "<br><br>")
%>
<p> </p>
<form method="GET" action="copyofenter_domain _name.asp" name="domain_search">
<p>enter domain name</p>
<p><input type="text" name="txtDomain" size="20"><select size="1" name="cmbExt">
<option selected>.com</option>
<option>.net</option>
</select></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
<p> </p>
<% Else
' Get input from the user. THe Request.Form() method
' can be used to get data from HTML forms submitted via
' the POST method.
domain = Request.Form ("txtDomain")
ext = Request.Form ("cmbExt")
test = domain & ext
'Response.Write ("The domain name selected is " & domain & ext)
response.write (test)
'****************** XML FILE CREATION ******************
' create a file system object
set fso = createobject("scripting.fi lesystemob ject")
' create the text file - true will overwrite any previous files
' Writes the db output to a .xml file in the same directory
Set act = fso.CreateTextFile(server. mappath("c ustomer.xm l"), true)
' All non repetitive xml on top goes here
act.WriteLine("<?xml version=""1.0"" encoding='UTF-8'?>")
act.WriteLine("<AvailableR equest>")
act.WriteLine("<RequestHea der>")
act.writeline("<VERSION_3_ 5></VERSIO N_3_5>")
act.writeline("<Authentica tion>")
act.writeline("<PartnerID> 18191849</ PartnerID> ")
act.writeline("<PartnerPas sword>2317 6</Partner Password>" )
act.writeline("</Authentic ation>")
act.writeline("<Comments>< /Comments> ")
act.writeline("</RequestHe ader>")
act.writeline("<Body>")
act.writeline("<VerifyDoma inName>" & test & "</VerifyDomainName>")
act.writeline("</Body>")
' All non repetitive xml on bottom goes here
act.WriteLine("</Available Request>")
' close the object (xml)
act.close
' Writes a link to the newly created xml document in the browser
response.write "<a href='customer.xml'>Custom er</a> (.xml) has been created <br>"
response.write "on " & now() & "<br>"
End If
%>
</body>
</html>
I tried to use MSXML core services but was unsuccesful.
What I am looking for is actual example of code that actually sends the xml file
to the server,recieve the reply(xml file) and then parse it to get the specific answer.
Appreciate your help!
My project is to create a banner on our companies website which actually allows our
customers to check the availability of a domain name of their choice.The domain name that they enter has to be embedded in an xml file Our hosting services have given us an API which actually defines the DTD's to be used ,the url of their server and the specific port that they want us send the xml file too.The reply that whether the domain name is available or not will also be sent to us as an xml file(the DTD of which is specified to) which I need to then parse and display the result to our user as to whether the domain name that they have entered is available or not.
I was able to generate the xml file dynamically based on the users input.The only problem is that I am unable to send it to the target server as desired.
Here is the header and an example of a xml file that the www.networksolutions.com(one with whom we register domains) people want us to use :
The following sample HTTP request illustrates the actual content that a client sends to the
Network Solutions server to accomplish a task (in this case a name availability request). This
example includes the header information section followed by the respective content information
section.
POST /invoke/Network Solutions.transactionproxy
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: text/xml
Content-length: 265
<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
<RequestHeader>
<VERSION_3_4></VERSION_3_4
<Authentication>
<PartnerID>123</PartnerID>
<PartnerPassword>partner</
</Authentication>
<Comments></Comments>
</RequestHeader>
<Body>
<VerifyDomainName>example.
</Body>
</AvailableRequest>
I tried to use MSXML core services but was unsuccesful.
**************************
************Here is the code that I am using which actually builds xml file dynamically***
**************************
<%@ LANGUAGE="VBScript" %>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
Sub SetValues()
Dim domain
Dim ext
domain=txtDomain
ext=cmbExt
End Sub
</SCRIPT>
<HTML>
<HEAD>
<title>New Page 1</title>
</script>
</head>
<body>
<%
Dim test
If (Request.Form.Item("txtDom
//domain = Request.Form ("txtDomain")
//ext = Request.Form ("cmbExt")
//Response.Write (domain & "." & ext & "<br><br>")
%>
<p> </p>
<form method="GET" action="copyofenter_domain
<p>enter domain name</p>
<p><input type="text" name="txtDomain" size="20"><select size="1" name="cmbExt">
<option selected>.com</option>
<option>.net</option>
</select></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
<p> </p>
<% Else
' Get input from the user. THe Request.Form() method
' can be used to get data from HTML forms submitted via
' the POST method.
domain = Request.Form ("txtDomain")
ext = Request.Form ("cmbExt")
test = domain & ext
'Response.Write ("The domain name selected is " & domain & ext)
response.write (test)
'****************** XML FILE CREATION ******************
' create a file system object
set fso = createobject("scripting.fi
' create the text file - true will overwrite any previous files
' Writes the db output to a .xml file in the same directory
Set act = fso.CreateTextFile(server.
' All non repetitive xml on top goes here
act.WriteLine("<?xml version=""1.0"" encoding='UTF-8'?>")
act.WriteLine("<AvailableR
act.WriteLine("<RequestHea
act.writeline("<VERSION_3_
act.writeline("<Authentica
act.writeline("<PartnerID>
act.writeline("<PartnerPas
act.writeline("</Authentic
act.writeline("<Comments><
act.writeline("</RequestHe
act.writeline("<Body>")
act.writeline("<VerifyDoma
act.writeline("</Body>")
' All non repetitive xml on bottom goes here
act.WriteLine("</Available
' close the object (xml)
act.close
' Writes a link to the newly created xml document in the browser
response.write "<a href='customer.xml'>Custom
response.write "on " & now() & "<br>"
End If
%>
</body>
</html>
I tried to use MSXML core services but was unsuccesful.
What I am looking for is actual example of code that actually sends the xml file
to the server,recieve the reply(xml file) and then parse it to get the specific answer.
Appreciate your help!
I can't see why you're writing the XML to the filesystem...don't you need to post it to the Netsol server? There is a ServerXMLHTTP Request object that is used for this purpose. The user POSTs the domain to your server, and you package up the request, and send it to Net Sol. Then you parse the response and put the result in your response back to the client. Here's an example (written in JScript, so you'll have to translate it, if you really want to use VBScript.
Regards,
Mike Sharp
/*
This code assumes that this XML template is already on the filesystem.
If not, build it using DOM methods
<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
<RequestHeader>
<VERSION_3_4/>
<Authentication>
<PartnerID>123</PartnerID>
<PartnerPassword></Partner Password>
</Authentication>
<Comments/>
</RequestHeader>
<Body>
<VerifyDomainName></Verify DomainName >
</Body>
</AvailableRequest>
*/
var xmlDoc = new ActiveXObject("Msxml2.DomD ocument")
xmlDoc.async=true;
try
{
xmlDoc.load(Server.MapPath ("template .xml");
}
catch(e)
{
//Handle error in case of problem with load
}
// now set the XML doc properties
var oNode = xmlDoc.selectSingleNode("A vailableRe quest/Body /VerifyDom ainName");
oNode.text = "domaintocheck.com";
var oNode = xmlDoc.selectSingleNode("A vailableRe quest/Requ estHeader/ Authentica tion/Partn erPassword ");
oNode.text = "mypassword";
var xmlHttp = new ActiveXObject("Msxml2.Serv erXMLHTTP" );
try
{
xmlHttp.Open("GET", s, false, xmlLogin.value, xmlPass.value);
}
catch(e)
{
// Put your error handling code here
}
// Set request headers as required
xmlHttp.setRequestHeader(" Content-ty pe", "text/xml");
// This POSTs the XML
xmlHttp.Send(xmlDoc);
if (!xmlHttp.responseXML.docu mentElemen t)
{
//Some servers don't send the contenttype correctly, and even
//though they send back good XML, the xmlHttp object fails to parse it
//especially where the URL doesn't end in .xml
//Serializing the XML isn't the best approach, but it works in those cases.
//one must be careful of encoding in this case.
xmlDoc.loadXML(xmlHttp.res ponseText) ;
}
else
{
xmlDoc.load(xmlHttp.respon seXML);
}
// Now xmlDoc contains the response, but xmlHttp.responseXML is
// also a fully parsed XML DOM object, and this last step isn't always necessary.
// I put it here to show how to hand servers that do not set contenttype correctly.
Regards,
Mike Sharp
/*
This code assumes that this XML template is already on the filesystem.
If not, build it using DOM methods
<?xml version="1.0" encoding="UTF-8"?>
<AvailableRequest>
<RequestHeader>
<VERSION_3_4/>
<Authentication>
<PartnerID>123</PartnerID>
<PartnerPassword></Partner
</Authentication>
<Comments/>
</RequestHeader>
<Body>
<VerifyDomainName></Verify
</Body>
</AvailableRequest>
*/
var xmlDoc = new ActiveXObject("Msxml2.DomD
xmlDoc.async=true;
try
{
xmlDoc.load(Server.MapPath
}
catch(e)
{
//Handle error in case of problem with load
}
// now set the XML doc properties
var oNode = xmlDoc.selectSingleNode("A
oNode.text = "domaintocheck.com";
var oNode = xmlDoc.selectSingleNode("A
oNode.text = "mypassword";
var xmlHttp = new ActiveXObject("Msxml2.Serv
try
{
xmlHttp.Open("GET", s, false, xmlLogin.value, xmlPass.value);
}
catch(e)
{
// Put your error handling code here
}
// Set request headers as required
xmlHttp.setRequestHeader("
// This POSTs the XML
xmlHttp.Send(xmlDoc);
if (!xmlHttp.responseXML.docu
{
//Some servers don't send the contenttype correctly, and even
//though they send back good XML, the xmlHttp object fails to parse it
//especially where the URL doesn't end in .xml
//Serializing the XML isn't the best approach, but it works in those cases.
//one must be careful of encoding in this case.
xmlDoc.loadXML(xmlHttp.res
}
else
{
xmlDoc.load(xmlHttp.respon
}
// Now xmlDoc contains the response, but xmlHttp.responseXML is
// also a fully parsed XML DOM object, and this last step isn't always necessary.
// I put it here to show how to hand servers that do not set contenttype correctly.
Nice bit of extra detail there, Mike. But wouldn't you want to do a POST instead of a GET?
;-)
>S'Plug<
;-)
>S'Plug<
Uh, yeah. That's what I "GET" for cutting and pasting!
Also, since I pasted this from somewhere else, this whole line is messed up, because I didn't specify the URL, either. It should be something like:
sUrl = //Path to the service endpoint
xmlHttp.Open("POST", sUrl, false );
Glad someone is around to keep me honest! ;^)
Regards,
Mike Sharp
Also, since I pasted this from somewhere else, this whole line is messed up, because I didn't specify the URL, either. It should be something like:
sUrl = //Path to the service endpoint
xmlHttp.Open("POST", sUrl, false );
Glad someone is around to keep me honest! ;^)
Regards,
Mike Sharp
.... oh and just to make sure you're extra honest... ;-)
surely xmlDoc.load(xmlHttp.respon seXML) would be have to be xmlDoc.load(xmlHttp.respon seXML.xml) although I would have thought that if the content type is wrong then xmlHttp.responseXML would not be valid anyway. Probably better to check xmlHttp.parseError.errorCo de.
>S'Plug<
surely xmlDoc.load(xmlHttp.respon
>S'Plug<
No, you want to use IStream, so that encoding is preserved. the .xml property serializes the XML, but does not provide a BOM, and that's burned me before. Now, if you really wanted to do that, you'd have to use loadXML. But since responseXML is a DomDocument object by itself, a simple assignment would also work:
var newXMLDoc = xmlHttp.responseXML
If the server has provided well-formed XML, but for some reason the xmlHttpResponseXML.documen tElement doesn't exist, you use the responseText property. My thoughts on the "why" of it are based on my observations during times when it would happen to me. It's hard to tell what the XMLHTTPRequest object is thinking sometimes.
Regards,
Mike Sharp
var newXMLDoc = xmlHttp.responseXML
If the server has provided well-formed XML, but for some reason the xmlHttpResponseXML.documen
Regards,
Mike Sharp
ASKER
Hello S'Plug,
Thank you for your posting .
I used your code but had one problem .
Your code has the following line
If Not oXMLData.LoadXML("<root><d ata value="test" /></root>") Then
How do I change this line so that my XML file(the one posted above) is loaded.
I wrote ("<AvailableRequest></Avai lableReque st>") but the output says
XML file not available.
Help is appreciated.
jd311
Waiting for your reply.
Thank you for your posting .
I used your code but had one problem .
Your code has the following line
If Not oXMLData.LoadXML("<root><d
How do I change this line so that my XML file(the one posted above) is loaded.
I wrote ("<AvailableRequest></Avai
XML file not available.
Help is appreciated.
jd311
Waiting for your reply.
Strange, this should work.
s="<AvailableRequest><Requ estHeader> <VERSION_3 _4></VERSI ON_3_4><Au thenticati on><Partne rID>123</P artnerID>< PartnerPas sword>part ner</Partn erPassword ></Authent ication><C omments></ Comments>< /RequestHe ader><Body ><VerifyDo mainName>e xample.com </VerifyDo mainName>< /Body></Av ailableReq uest>"
If Not oXMLData.LoadXML(s) Then
.....
Are you sure that you are calling LoadXML() and not just Load()? This seems like it might be the case from your error message "XML file not available". The Load() method is used to load the XML from a file whereas LoadXML() loads from a string. See http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_mth_hn_1nho.asp?frame=true
>S'Plug<
s="<AvailableRequest><Requ
If Not oXMLData.LoadXML(s) Then
.....
Are you sure that you are calling LoadXML() and not just Load()? This seems like it might be the case from your error message "XML file not available". The Load() method is used to load the XML from a file whereas LoadXML() loads from a string. See http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_mth_hn_1nho.asp?frame=true
>S'Plug<
ASKER
Hi S'Plug
Yes I did try your idea.
I am using LoadXML().
I got the following error.
msxml4.dll (0x80070005)
Access is denied
Help appreciated.
jd311.
**points increased**
Yes I did try your idea.
I am using LoadXML().
I got the following error.
msxml4.dll (0x80070005)
Access is denied
Help appreciated.
jd311.
**points increased**
ASKER
Hi,
I played around a bit and was able to overcome the "Access is denied" error.
Now I am getting the following error
"<Error>Could not get XML data</Error>"
What could be the possible reasons for this.
Also while writing the url where I need to POST should I write
"https://www.networksolutions.com/" OR "http://www.networksolutions.com/"
(Note the http & https)
If I use http it gives me "Could not get XML data" while if I use https connection gets timed out
Please help.
jd311
I played around a bit and was able to overcome the "Access is denied" error.
Now I am getting the following error
"<Error>Could not get XML data</Error>"
What could be the possible reasons for this.
Also while writing the url where I need to POST should I write
"https://www.networksolutions.com/" OR "http://www.networksolutions.com/"
(Note the http & https)
If I use http it gives me "Could not get XML data" while if I use https connection gets timed out
Please help.
jd311
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In ASP you can use ServerXMLHTTP to post XML data to an external server
Set oXMLData = Server.CreateObject("MSXML
oXMLData.async = false
If Not oXMLData.LoadXML("<root><d
Set oErr = xml.parseError
sErrMsg = "XML Parsing Error. File: " & oErr.url & " Reason : " & oErr.reason & " Line: " & oErr.line & ", Character: " & oErr.linepos & ", Text: " & oErr.srcText
Err.Raise 999, sErrMsg
End If
Set oXMLHTTP = Server.CreateObject("MSXML
oXMLHTTP.open "POST", "http://someserver/respond.asp", false
oXMLHTTP.send(oXMLData) ' Send the XML.
Response.ContentType = "text/xml";
If Not oXMLHTTP.status = 200 Then
Response.Write "<Error>Could not get XML data.</Error>"
End If
Response.Write (oXMLHTTP.responseXML.xml)
For more information on ServerXMLHTTP look here: http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_obj_iserverxmlhttprequest_5115.asp
Hope this helps,
>S'Plug<