472,342 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

Simple ASP scripting question?

I'm not that great with ASP but I've hacked together a simple server
side script that uses the Microsoft XML ServerXMLHTTP object. The
problem is that when other people use the script sometimes they get an
error that the object can not be created, due likely to the required
Microsoft XML libraries not being installed. I'd like to try creating
the XMLHTTP object in an if/else block so that if the object can not be
created then it tries another object creation approach... here is the
code I'm using to create the object:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");

The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");

Can someone provide me with the code snippet that will result in the
variable objSrvHTTP having a ServerXMLHTTP object inside that works?
Also, if there are other variations on that object name then please
include those objects as well...

FYI, I'm only using open, setRequestHeader, send and responseText
methods on the object.

Thanks,
Cliff.

Aug 24 '06 #1
7 7912


Cliff wrote:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");

The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");
var progIds = [
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
var httpRequest = null;
for (var i = 0, l = progIds.length; i < l; i++) {
try {
httpRequest = new ActiveXObject(progIds[i]);
break;
}
catch (e) {}
}
if (httpRequest != null) {
// make your request here
}
else {
// no object found
}

There are also MSXML 5 and 6 so depending on what you do expect on the
server you could use e.g.

var progIds = [
'Msxml2.ServerXMLHTTP.6.0',
'Msxml2.ServerXMLHTTP.5.0',
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 24 '06 #2
Try using the generic object:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");

Brian
Aug 24 '06 #3
"Cliff" <cl***@thesolutioncafe.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
I'm not that great with ASP but I've hacked together a simple server
side script that uses the Microsoft XML ServerXMLHTTP object. The
problem is that when other people use the script sometimes they get an
error that the object can not be created, due likely to the required
Microsoft XML libraries not being installed. I'd like to try creating
the XMLHTTP object in an if/else block so that if the object can not be
created then it tries another object creation approach... here is the
code I'm using to create the object:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");

The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");

Can someone provide me with the code snippet that will result in the
variable objSrvHTTP having a ServerXMLHTTP object inside that works?
Also, if there are other variations on that object name then please
include those objects as well...

FYI, I'm only using open, setRequestHeader, send and responseText
methods on the object.
Will this help? You can test is as-is.

<html>
<head>
<title>xmlhttpx.html</title>
<script type="text/javascript">
function getRequestObj() {
var ret = null;
var xml = [
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"];
if (window.ActiveXObject) {
for (var i=0; i<xml.length; i++) {
try {
ret = new ActiveXObject(xml[i]);
break;
} catch(e) {}
}
} else if(window.XMLHttpRequest) {
try {
ret = new XMLHttpRequest();
} catch(e) {}
}
return ret;
}

var sURL = "http://www.gabocorp.com/";
var oXML = getRequestObj();
oXML.open("GET",sURL,false);
oXML.send();

alert(oXML.responseText);
</script>
</head>
<body>
</body>
</html>
Also, check out this link:

Identify which components are installed on the server.
<URL:
http://www.planet-source-code.com/vb...odeId=8976&lng
WId=4>

It can be adapted to run on any user's PC as a VBS file instead of ASP.
Just remove "<%", "%>", "Server.", and "<BR>"
and change "Response.Write" to "WScript.Echo"
then save it as "Components.vbs" and run it via the command line
"cscript.exe //nologo Components.vbs Components.txt"
Aug 24 '06 #4
This looks like it worked perfectly. Is there any advantage or
disadvantage to the order of object creation, for example, are newer
versions of the object more security constrained? Also, is it possible
to avoid going through the loop each time the page is called once the
appropriate library has been determined?

Cliff.
Martin Honnen wrote:
Cliff wrote:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");

The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");

var progIds = [
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
var httpRequest = null;
for (var i = 0, l = progIds.length; i < l; i++) {
try {
httpRequest = new ActiveXObject(progIds[i]);
break;
}
catch (e) {}
}
if (httpRequest != null) {
// make your request here
}
else {
// no object found
}

There are also MSXML 5 and 6 so depending on what you do expect on the
server you could use e.g.

var progIds = [
'Msxml2.ServerXMLHTTP.6.0',
'Msxml2.ServerXMLHTTP.5.0',
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '06 #5


Cliff wrote:
Is there any advantage or
disadvantage to the order of object creation, for example, are newer
versions of the object more security constrained?
There are differences, consult the MSXML SKD for details, it is online here
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_xmlprod.asp>
Also, is it possible
to avoid going through the loop each time the page is called once the
appropriate library has been determined?
Change the code to store the program id that could be successfully
created and used that program id from there one.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '06 #6

"Cliff" <cl***@thesolutioncafe.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
I'm not that great with ASP but I've hacked together a simple server
side script that uses the Microsoft XML ServerXMLHTTP object. The
problem is that when other people use the script sometimes they get an
error that the object can not be created, due likely to the required
Microsoft XML libraries not being installed. I'd like to try creating
the XMLHTTP object in an if/else block so that if the object can not be
created then it tries another object creation approach... here is the
code I'm using to create the object:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");

The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");

Can someone provide me with the code snippet that will result in the
variable objSrvHTTP having a ServerXMLHTTP object inside that works?
Also, if there are other variations on that object name then please
include those objects as well...

FYI, I'm only using open, setRequestHeader, send and responseText
methods on the object.
I just stick with MSXML2.ServerXMLHTTP.3.0 it's always there on Win2K above
and I know exactly what I'm getting and what it can and can't do.
Thanks,
Cliff.

Aug 29 '06 #7
Cliff.
Martin Honnen wrote:
Cliff wrote:

var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP.4.0");
>
The above line often fails because the object doesn't exist so I would
like to trap the error and try to create the object like:
>
var objSrvHTTP=Server.CreateObject("MSXML2.ServerXMLHT TP");
var progIds = [
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
var httpRequest = null;
for (var i = 0, l = progIds.length; i < l; i++) {
try {
httpRequest = new ActiveXObject(progIds[i]);
break;
}
catch (e) {}
}
if (httpRequest != null) {
// make your request here
}
else {
// no object found
}

There are also MSXML 5 and 6 so depending on what you do expect on the
server you could use e.g.

var progIds = [
'Msxml2.ServerXMLHTTP.6.0',
'Msxml2.ServerXMLHTTP.5.0',
'Msxml2.ServerXMLHTTP.4.0',
'Msxml2.ServerXMLHTTP.3.0',
'Msxml2.ServerXMLHTTP'
];
Cliff wrote:
This looks like it worked perfectly. Is there any advantage or
disadvantage to the order of object creation, for example, are newer
versions of the object more security constrained? Also, is it possible
to avoid going through the loop each time the page is called once the
appropriate library has been determined?
Why even do that? I mean, the object is on the server, not the client.
Just figure out which one you have on your server and store it in an
application variable.

If you maintain your own server, it's even easier, since you should
know what libraries are on it and if/when they're updated.

Aug 29 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trimbitas Sorin | last post by:
Hello I have a simple syntax question : What does the following line mean: 1: %checkType; ?? I know that @test="" is an array and $test="" is a...
13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a...
3
by: msnews.microsoft.com | last post by:
Hello All, In the "Find Dialog" (Ctrl-F) of the IDE there is an option called "Mark All". When I click "Mark All", this marks the occurences...
7
by: Scott Frankel | last post by:
Still too new to SQL to have run across this yet ... How does one return the latest row from a table, given multiple entries of varying data?...
1
by: adam | last post by:
I have a simple form question. I order to access a payment gateway I have a asp.net page which has to have a form that use POST for method and...
6
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This...
3
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple...
3
by: Ashik | last post by:
I have a simple compilation question, but I haven't been able to find an answer for it anywhere online. I've made a simplified version of my...
5
by: Oriane | last post by:
Hi, With Asp.net 2.0, when a internet user logs in with a "login authentication form", is the password encrypted when it is sent to the server ?...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.