How can i fecth the content of an url (thats not stored in my web server) and return it to my asp page ( the one who is responsible for calling this url)?
Assuming you want the end output (not the source ASP code) of a remote page, use the MSXML2.XMLHTTP object.
<script runat="server" language="javascript">
try{
var url = new String(Request.QueryString("url");
if (url != "undefined"{
var http = Server.CreateObject("MSXML2.XMLHTTP"
http.open("GET", url, false);
http.send();
Response.write(http.responseText);
// Above line is where you'd do something else with the
// returned resource - say, xml or regex parse it.
http = null;
}else Response.write("add url param to querystring."
}catch(e){Response.write(e.description);}
</script>
codestorm
Newbie Life Member.
Fire bad. Tree pretty. - Buffy
<insert witticism here>
That's work fine for me! Thenk you.
Now i have another problem...
As i said before i want to fetch the output of a page, using asp code. This XMLHTTP componet works fine to do it, but the information i want is not appearing because i need the session. How can i get the session of a page and pass it to the next page on the sequence iam trying to reach?
For example, I do the login very well and it opens the next page. Futher i want to go to a second page that is not showing all the data because i don´t have the session. How can i make this work?
Ahhh, that is trickier. I'm having trouble myself at the moment getting cookies through the XMLHTTP object.
Someone told me to just use the getResponseHeader and getAllResponseHeaders methods, but the cookies don't appear using those methods.
To rewind a bit, in order to request a second page after passing form data with a first XMLHTTP request sent to a login page (takes a breath), you'll need to retrieve the cookie the login page response will generally send - this is what I'm having difficulty doing.
You /could/ instead simply pass hidden form variables about to maintain state, but I personally consider that about as tacky as relying on IIS Session (which I might add should I believe also be passed as a cookie to the XMLHTTP object anyway - an ASPSessionID handle to the server-side Session).
codestorm
Newbie Life Member.
Fire bad. Tree pretty. - Buffy
<insert witticism here>
I found something.
IHTMLDocument2 interface has a Cookie property that returns a list of all cookies specific to the current page.These cookies are then sent to the server in the HTTP request headers.
And theres an example:
Public Sub Send()
On Error GoTo eh
Dim oXMLHTTP As MSXML.XMLHTTPRequest
Dim objDoc As IHTMLDocument2
Set oXMLHTTP = New MSXML.XMLHTTPRequest
oXMLHTTP.open "POST", mServerURL, False
'send any document cookies
Set objDoc = UserControl.Parent
If Len(objDoc.cookie) > 0 Then
oXMLHTTP.setRequestHeader "Cookie", objDoc.cookie
End If
'send request
oXMLHTTP.Send moRequestDoc
Set moRequestDoc = Nothing 'reinit
If oXMLHTTP.responseXML.xml = "" Then
MsgBox "No valid reponse returned. " & _
vbCrLf & "Response text is: " & _
oXMLHTTP.responseText, vbCritical, "XIR Client"
Else
'retrieve response
Set moResponseDoc = oXMLHTTP.responseXML
End If
Exit Sub
eh:
MsgBox "Error sending request: " & vbCrLf & Err.Description
End Sub
But i can´t make it work iam receiving error messages.
Do you know what´s wrong with this example? Or how can i use the IHTMLDocument2?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.