Notifications
Clear all

[Closed] ActiveXObject("ADODB.Stream") get url data?

Hello everyone,
Does anyone know about ActiveXObject(“ADODB.Stream”)?I need to use it to get web data for my project,what I know the Microsoft jscript(.js) can do it ,and I have an example,I am going to try convert it to maxscript,but 3dsmax does not work for the codes:
Jscript original codes:

var oXmlHttp = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
oXmlHttp.open("GET","https://www.yahoo.com", false);
oXmlHttp.send()
var oStream = new ActiveXObject("ADODB.Stream");
{
oStream.Type=1;
oStream.Mode=3;
oStream.Open() ;
oStream.Write(oXmlHttp.responseBody);
oStream.Position= 0;
oStream.Type= 2;
oStream.Charset="gb2312";
var result= oStream.ReadText();
oStream.Close();
oStream = null;
WScript.Echo( result);
}

The codes I was translated,cause error

(
    rollout httpSock "httpSock" width:0 height:0 (activeXControl port "Microsoft.XMLHTTP" setupEvents:false releaseOnClose:false);
    createDialog httpSock pos:[-100,-100];destroyDialog httpSock;	
    oXmlHttp= httpSock.port	
	
	oXmlHttp.open "GET" "https://www.yahoo.com" false
    oXmlHttp.send();
	
	rollout httpSock "httpSock" width:0 height:0 (activeXControl port "ADODB.Stream" setupEvents:false releaseOnClose:false);
	createDialog httpSock pos:[-100,-100];destroyDialog httpSock;    	
	oStream = httpSock.port
	
	if oXmlHttp.readyState==4 then
	(		
        oStream.Type=#adTypeBinary
	oStream.Mode=#adModeWrite
	oStream.open();
	oStream.Write oXmlHttp.responseBody; -- Runtime error: Unable to place variant into OLE SAFEARRAY: Bad variable type.; value: 3P <<
	oStream.Position= 0;
	oStream.Charset="gb2312"; -- Runtime error: Cannot set the property, .Charset << 
	result= oStream.ReadText();	-- Runtime error: ComObject method call failed, ReadText() <<
	oStream.Close();
	oStream =undefined;	
	print result
	)
)
5 Replies

why do you need exactly ADODB.Stream? you can use .net FileStream, can’t you?

1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

I tried,I used (dotNetClass “system.Net.WebRequest”),sometimes not response even I can visit url site normally,is the “.net FileStream” as same as dotNetClass “system.Net.WebRequest”?Is there an example?

ADODB.Stream is just a pretty old thing for stream reading/writing… depending on what you want to read/write you can use StreamReader/StreamWriter or FileStream.

what do you want to read or write?

1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

I just want to read text of a url line such as:(Only read function)
http://en.wikipedia.org/wiki/Text
the whole text(html format is ok)
I want to store necessary data for my website,and then read it from maxscript

I got an example,is this way right?why I got txt=”” after run?

url="http://en.wikipedia.org/wiki/Text"
wc=dotNetClass "System.Net.WebClient"
sr=dotNetClass "System.IO.StreamReader"
wcobj=(dotNetObject wc)
wcobj.Headers.Add "user-agent:xxx"
stm=wcobj.OpenRead url
srobj=dotNetObject sr stm
txt=srobj.ReadToEnd()
srobj.Close()
print txt