paygo
asked on
MSXML2.ServerXMLHTTP with C# Scripting? HOW TO???
Hi, I know C#, but not VB.
How do I create the equivalent C# script for this VB Syntax?
Set xml Server.CreateObject("MSXML 2.ServerXM LHTTP")
Thanks
complete function is here. but I can do the rest out, once I get the correct Objects.
<%
Function GetContent(url)
Dim xmlHttp
Set xml = Server.CreateObject("MSXML 2.ServerXM LHTTP")
xml.Open "GET", url, True
Call xml.Send()
If xml.readyState <> 4 Then
xml.waitForResponse 3
End If
If Err.Number <> 0 Then
Else
If (xml.readyState <> 4) Or (xml.Status <> 200) Then
xml.Abort
strData = "Problem communicating with remote server..."
Else
strData = xml.ResponseText
End If
End If
GetContent = strData
End Function
%>
<%=GetContent("http://oldlook.experts-exchange.com/")%>
How do I create the equivalent C# script for this VB Syntax?
Set xml Server.CreateObject("MSXML
Thanks
complete function is here. but I can do the rest out, once I get the correct Objects.
<%
Function GetContent(url)
Dim xmlHttp
Set xml = Server.CreateObject("MSXML
xml.Open "GET", url, True
Call xml.Send()
If xml.readyState <> 4 Then
xml.waitForResponse 3
End If
If Err.Number <> 0 Then
Else
If (xml.readyState <> 4) Or (xml.Status <> 200) Then
xml.Abort
strData = "Problem communicating with remote server..."
Else
strData = xml.ResponseText
End If
End If
GetContent = strData
End Function
%>
<%=GetContent("http://oldlook.experts-exchange.com/")%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, you can put the function in the code behind that goes with the page.
try this in JS
<body onload="init()">
<input value="view Yahoo" type="button" onclick="alert(document.ge tElementBy Id('yahoo' ).innerHTM L)">
<input value="view ebay"type="button" onclick="alert(document.ge tElementBy Id('ebay') .innerHTML )"> <p>
<script>
function LoadPage(theURL,theID){
var objSrvHTTP;
try{
objSrvHTTP = new ActiveXObject("Msxml2.XMLH TTP.4.0");
}
catch(e){
try{
objSrvHTTP = new ActiveXObject("Msxml2.XMLH TTP");
}
catch(e){
try{
objSrvHTTP = new ActiveXObject("Microsoft.X MLHTTP");
alert("ok you have Microsoft.XMLHTTP")
}
catch(e){
alert("you need install MSXML 4.0, http://www.microsoft.com/downloads/");
return;
}
}
}
objSrvHTTP.open ("GET",theURL,false);
objSrvHTTP.send ("");
document.getElementById(th eID).inner HTML=objSr vHTTP.resp onseText;
}
function init(){
LoadPage("http://www.yahoo.com","yahoo")
LoadPage("http://www.ebay.com","ebay")
}
</script>
<body onload="init()">
<input value="view Yahoo" type="button" onclick="alert(document.ge
<input value="view ebay"type="button" onclick="alert(document.ge
<script>
function LoadPage(theURL,theID){
var objSrvHTTP;
try{
objSrvHTTP = new ActiveXObject("Msxml2.XMLH
}
catch(e){
try{
objSrvHTTP = new ActiveXObject("Msxml2.XMLH
}
catch(e){
try{
objSrvHTTP = new ActiveXObject("Microsoft.X
alert("ok you have Microsoft.XMLHTTP")
}
catch(e){
alert("you need install MSXML 4.0, http://www.microsoft.com/downloads/");
return;
}
}
}
objSrvHTTP.open ("GET",theURL,false);
objSrvHTTP.send ("");
document.getElementById(th
}
function init(){
LoadPage("http://www.yahoo.com","yahoo")
LoadPage("http://www.ebay.com","ebay")
}
</script>
One note on the C# script, you need to put the script tags around it, not the <% %>. Also, it should go inside the html <head></head>. :
<script runat="server >
... function here...
</script>
Then in the body:
<% Response.Output.Write(GetC ontent("http://oldlook.experts-exchange.com/") )%>
<script runat="server >
... function here...
</script>
Then in the body:
<% Response.Output.Write(GetC
One of these times I'll get it right - missed a closing quote:
<script runat="server" >
... function here...
</script>
Or put it in the code behind as previously indicated.
<script runat="server" >
... function here...
</script>
Or put it in the code behind as previously indicated.
ASKER
thanks drichards,
this is correct - but I get an msxml4.dll access is denied on some sites.
this is correct - but I get an msxml4.dll access is denied on some sites.
Is that an HTTP status 401 or 403? You can check for those as well.