I'm trying to run a .NET program on Ubuntu using mono.
Program connects to remote server API and gets XML string as response. Here's a simplified version of function responsible for this task.
using System.Net;
static string GetProducts(string clientID, string apiKey, string url)
{
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
req.Credentials = new NetworkCredential(clientID, apiKey);
req.ContentType = "application/x-www-form-urlencoded";
string result = string.Empty;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
return result;
}
It works perfectly well on my Windows 8.1 machine. But my goal is to run it on Ubuntu VPS. I'm using mono to achieve that. Program runs, but stops with exception when it tries to parse downloaded XML string.
[ERROR] FATAL UNHANDLED EXCEPTION: System.Xml.XmlException: Document element did not appear. Line 1, position 1.
With a little probing I found out that the program isn't actually getting response in XML but produces an empty string instead. Which is odd as no connection errors are being thrown.
I've had some previous experience with mono and Ubuntu, but never ran into problem like this before.
Could it be something to do with Ubuntu server or mono? Or is in the code itself?
Any thoughts on this?