By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,495 Members | 1,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,495 IT Pros & Developers. It's quick & easy.

ASP VBScript JScript confusion

P: 1
I dont know where to start my question so let me tell you my story :)

The ASP that cause me trouble is running on IIS that set ASP default language to JScript instead of VBScript.

This ASP page is popped up by another ASP page and there are authentication, privilege and security stuff involved. And yes this page contain a lot of javascript.

there is a <DIV></DIV> in this page for me. And my job is as simple as put another page between that tag.

Yes it's that easy. It like ... I love your web site and I want to show your homepage of your website in the middle of my page.

and I found this script on the internet

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Private Function GetWebPage(ByVal HTTPAddress, ByVal CharSet)
  3.     Dim strContent, xml_http, strBody, strText, max
  4.     '--- Fetch the web page
  5.     On error resume next
  6.     Set xml_http = Server.CreateObject("Microsoft.XMLHTTP")
  7.         xml_http.Open "GET", HTTPAddress, False
  8.         xml_http.Send
  9.         If Err Then
  10.             GetWebPage = ""
  11.             Exit Function
  12.         End If
  13.         strContent = xml_http.responseBody
  14.     Set xml_http = Nothing
  15.     On Error GoTo 0
  16.     '--- Converts the binary content to text
  17.       '--- Create Stream object
  18.       Dim BinaryStream
  19.       Set BinaryStream = CreateObject("ADODB.Stream")
  20.       '--- Specify stream type - we want To save text/string data.
  21.       BinaryStream.Type = 1
  22.       '--- Open the stream And write text/string data To the object
  23.       BinaryStream.Open
  24.       BinaryStream.Write strContent
  25.       '--- Change stream type To binary
  26.       BinaryStream.Position = 0
  27.       BinaryStream.Type = 2
  28.       '--- Specify charset For the source text (unicode) data.
  29.       If Len(CharSet) > 0 Then
  30.         BinaryStream.CharSet = CharSet
  31.       Else
  32.         BinaryStream.CharSet = "UTF-8"
  33.       End If
  34.       '--- Open the stream And get binary data from the object
  35.       strText = BinaryStream.ReadText
  36.         '--- remove headers
  37.         max = InStr(1, strText, Chr(10) & Chr(10), 1)
  38.         GetWebPage = Mid(strText, max + 1)
  39. End Function
  40. Dim strPage
  41. strPage = GetWebPage( "http://www.livio.net/main/default.asp", "" )
  42.  '--- get the html source of the livio.net home page and store it into the variable strPage.
  43. Response.Write (strPage)
  44. %>
  45. <html>
  46. <body>
  47. </body>
  48. </html>
  49.  
it works fine by itself. But I can not put this in my code because my page use JScript

I found another script on another website that help me use both jscript and vbscript using 2 .asp

the first asp is page1.asp

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>My page</title>
  3. <body>
  4. <script language="javascript" src="page2.asp"></script> 
  5. </body>
  6. </html>
  7.  

the secondpage asp is page2.asp

Expand|Select|Wrap|Line Numbers
  1. <%@ language="VBScript"%>
  2. <%
  3. strPage = "Hello"
  4. %>
  5. document . write ("<%=strPage%>")
  6.  
this also work fine.

So I tried to put the first script I found in the first website in the page2.asp like this

page2.asp
Expand|Select|Wrap|Line Numbers
  1. <%@ language="VBScript"%>
  2. <%
  3. Private Function GetWebPage(ByVal HTTPAddress, ByVal CharSet)
  4.     Dim strContent, xml_http, strBody, strText, max
  5.     '--- Fetch the web page
  6.     On error resume next
  7.     Set xml_http = Server.CreateObject("Microsoft.XMLHTTP")
  8.         xml_http.Open "GET", HTTPAddress, False
  9.         xml_http.Send
  10.         If Err Then
  11.             GetWebPage = ""
  12.             Exit Function
  13.         End If
  14.         strContent = xml_http.responseBody
  15.     Set xml_http = Nothing
  16.     On Error GoTo 0
  17.     '--- Converts the binary content to text
  18.       '--- Create Stream object
  19.       Dim BinaryStream
  20.       Set BinaryStream = CreateObject("ADODB.Stream")
  21.       '--- Specify stream type - we want To save text/string data.
  22.       BinaryStream.Type = 1
  23.       '--- Open the stream And write text/string data To the object
  24.       BinaryStream.Open
  25.       BinaryStream.Write strContent
  26.       '--- Change stream type To binary
  27.       BinaryStream.Position = 0
  28.       BinaryStream.Type = 2
  29.       '--- Specify charset For the source text (unicode) data.
  30.       If Len(CharSet) > 0 Then
  31.         BinaryStream.CharSet = CharSet
  32.       Else
  33.         BinaryStream.CharSet = "UTF-8"
  34.       End If
  35.       '--- Open the stream And get binary data from the object
  36.       strText = BinaryStream.ReadText
  37.         '--- remove headers
  38.         max = InStr(1, strText, Chr(10) & Chr(10), 1)
  39.         GetWebPage = Mid(strText, max + 1)
  40. End Function
  41. Dim strPage
  42. strPage = GetWebPage( "http://www.livio.net/main/default.asp", "" )
  43.  '--- get the html source of the livio.net home page and store it into the variable strPage.
  44. 'Response.Write (strPage)
  45. %>
  46.  
  47. document . write ("<%=strPage%>")
  48.  
it doesn't work.

I tried to use Response.write it doesn't work too.

so I tried a fews other things too.

1. after statement
strPage = GetWebPage( "http://www.livio.net/main/default.asp", "" )

I tried
strPage = Len(strPage)
and it show a number on my page then I think this is not far from the answer.

I tried
strPage = Mid(strPage, 100, 10)

and it show some string on my page

I found out that in fact this strPage is a string that have a lot of double quote in it and that seem to be a lot of trouble for document . write

so my question are

1. Why Response.Write (strPage) did not work in this case?
2. document . write ("<%=strPage%>") seem to work with out double quote, how ca i fix it?
3. Is there other ways to do this?
Apr 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
Hi tunk!

There's a very simple solution to this problem...
at first; just forget use of any ADODB ~ objects
You can get the binary data outright from the XML object
in the following way...
Expand|Select|Wrap|Line Numbers
  1.        Dim xml_http, bStr, strContent
  2.        Set xml_http = Server.CreateObject("Microsoft.XMLHTTP")
  3.  
  4.        'use POST method for large amount of data
  5.         xml_http.Open "GET", HTTPAddress, False
  6.         xml_http.Send
  7.  
  8.        ' your error-handling thing
  9.        '....        
  10.  
  11.         bStr = xml_http.responseBody
  12.         Set xml_http = Nothing
  13.  
  14.        For i = 1 to LenB(bStr)
  15.         strContent = strContent & Chr(AscB(MidB(bStr, i, 1)))
  16.       Next
  17.  
  18.       Response.Write(strContent)
  19.  
' and that's all

I hope you can find this useful

-Nea-
Oct 28 '07 #2

P: 2
Hi again tunk!

one more little thing...

'add the following line next the .send command

xml_http.getAllResponseHeaders

regards
-Nea-
Oct 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.