Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading remote file [C#]

Tags:

c#

asp.net

I am trying to read a remote file using HttpWebRequest in a C# Console Application. But for some reason the request is empty - it never finds the URL.

This is my code:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://uo.neverlandsreborn.org:8000/botticus/status.ecl");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

How come this is not possible?

The file only contains a string. Nothing more!

like image 494
janhartmann Avatar asked Nov 22 '25 02:11

janhartmann


1 Answers

How are you reading the response data? Does it come back as successful but empty, or is there an error status?

If that doesn't help, try Wireshark, which will let you see what's happening at the network level.

Also, consider using WebClient instead of WebRequest - it does make it incredibly easy when you don't need to do anything sophisticated:

string url = "http://uo.neverlandsreborn.org:8000/botticus/status.ecl";
WebClient wc = new WebClient();
string data = wc.DownloadString(url);
like image 113
Jon Skeet Avatar answered Nov 24 '25 18:11

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!