Notifications
Clear all

[Closed] dotnet webclient question~

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
 lo1
(@lo1)
Joined: 10 months ago

Posts: 0

well… you copied the URL wrong.

(@easyfrog)
Joined: 10 months ago

Posts: 0

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

 lo1

sorry, what?

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

1 Reply
(@easyfrog)
Joined: 10 months ago

Posts: 0

??? your means the code of the script is work for you?? 😮 can you show me what is the “correct header “

 lo1

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()