PDA

View Full Version : dotnet webclient question~


easyfrog
06-26-2011, 07:31 AM
hello~

I want to use dotnet webclient to request a URL to get the info.

this is the C# code:(it is works well)

WebClient wb=new WebClient();

wb.Headers.Add("user-agent:xxx");

Stream stm=wb.OpenRead("http://cglobal.0fees.net/t.txt");

StreamReader sr=new StreamReader(stm);
Console.WriteLine(sr.ReadToEnd());

and this is the code of maxscript :

url="http://global.0fees.net/t.txt"
--WebClient
wc=dotNetClass "System.Net.WebClient"

--StreamReader
sr=dotNetClass "System.IO.StreamReader"

--create a wc instacne
wcobj=(dotNetObject wc)
wcobj.Headers.Add "UserAgent:xxx"
stm=wcobj.OpenRead url

srobj=dotNetObject sr stm

txt=srobj.ReadToEnd()

--close
srobj.Close()

it's use the same method of the C# code . BUT it's return a question of :
"-- Runtime error: dotNet runtime exception: The remote server returned an error: (403) Forbidden."

somebody can tell me where i went wrong ??~ :banghead:

lo
06-26-2011, 08:51 AM
well.. you copied the URL wrong.

hello~

I want to use dotnet webclient to request a URL to get the info.

this is the C# code:(it is works well)

WebClient wb=new WebClient();

wb.Headers.Add("user-agent:xxx");

Stream stm=wb.OpenRead("http://cglobal.0fees.net/t.txt");

StreamReader sr=new StreamReader(stm);
Console.WriteLine(sr.ReadToEnd());

and this is the code of maxscript :

url="http://global.0fees.net/t.txt"
--WebClient
wc=dotNetClass "System.Net.WebClient"

--StreamReader
sr=dotNetClass "System.IO.StreamReader"

--create a wc instacne
wcobj=(dotNetObject wc)
wcobj.Headers.Add "UserAgent:xxx"
stm=wcobj.OpenRead url

srobj=dotNetObject sr stm

txt=srobj.ReadToEnd()

--close
srobj.Close()

easyfrog
06-26-2011, 08:58 AM
well.. you copied the URL wrong.


haha ~ :applause: I hope this is the wrong place. BUT the error still have ~ :banghead: :banghead:

lo
06-26-2011, 09:06 AM
sorry, what?

It works for me with the correct header and URL spelling.

easyfrog
06-26-2011, 09:11 AM
sorry, what?

It works for me with the correct header and URL spelling.


????? your means the code of the script is work for you?? :eek: can you show me what is the "correct header "

lo
06-26-2011, 09:18 AM
It's the same code you posted but with correct spelling of URL and Header.

url="http://cglobal.0fees.net/t.txt"
--WebClient
wc=dotNetClass "System.Net.WebClient"

--StreamReader
sr=dotNetClass "System.IO.StreamReader"

--create a wc instacne
wcobj=(dotNetObject wc)
wcobj.Headers.Add "user-agent:xxx"
stm=wcobj.OpenRead url

srobj=dotNetObject sr stm

txt=srobj.ReadToEnd()

--close
srobj.Close()

CGTalk Moderation
06-26-2011, 09:18 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.