Notifications
Clear all
[Closed] dotnet webclient question~
Jun 26, 2011 7: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 :
[B] "-- Runtime error: dotNet runtime exception: The remote server returned an error: (403) Forbidden."[/B]
somebody can tell me where i went wrong ??~ :banghead:
5 Replies
2 Replies
haha ~ :applause: I hope this is the wrong place. BUT the error still have ~ :banghead: :banghead:
1 Reply
??? your means the code of the script is work for you?? 😮 can you show me what is the “correct header “
Jun 26, 2011 7:31 am
It’s the same code you posted but with correct spelling of URL and Header.
url="[B] http://cglobal.0fees.net/t.txt [/B]"
--WebClient
wc=dotNetClass "System.Net.WebClient"
--StreamReader
sr=dotNetClass "System.IO.StreamReader"
--create a wc instacne
wcobj=(dotNetObject wc)
wcobj.Headers.Add "[B]user-agent:xxx[/B]"
stm=wcobj.OpenRead url
srobj=dotNetObject sr stm
txt=srobj.ReadToEnd()
--close
srobj.Close()