コード例 #1
0
ファイル: KSAPI.cs プロジェクト: Rusk85/CKAN
        public static string Call(string path)
        {
            // TODO: There's got to be a better way than using regexps.
            // new Uri (kerbalstuff_api, path) doesn't work, it only uses the *base* of the first arg,
            // and hence drops the /api path.

            // Remove leading slashes.
            path = Regex.Replace(path, "^/+", "");

            string url = kerbalstuff_api + path;

            log.DebugFormat("Calling {0}", url);
            try
            {
                using (var web = new Web())
                {
                    return web.DownloadString(url);
                }
            }
            catch (DllNotFoundException)
            {
                //Curl is not installed. Curl is a workaround for a mono issue.
                //TODO Richard - Once repos are merged go and check all Platform calls to see if they are mono checks
                if (!Platform.IsWindows) throw;
                //On mircrosft.net so try native code.
                using (var web = new WebClient())
                {
                    try
                    {
                        return web.DownloadString(url);
                    }
                    catch (WebException web_ex)
                    {
                        log.ErrorFormat("WebException while accessing {0}: {1}", url, web_ex);
                        throw;
                    }
                }
            }
        }