コード例 #1
0
        internal async Task <string> QueryAsync(string request, bool oauth, bool cfid, int wait)
        {
            string parameters = "?&ref=&cors=&_=" + GetTimestamp();

            if (request.Contains("?"))
            {
                parameters = parameters.Substring(1);
            }

            if (oauth)
            {
                parameters += "&oauth=" + OauthKey;
            }
            if (cfid)
            {
                parameters += "&csrf=" + CfidKey;
            }

            if (wait != -1)
            {
                parameters += "&returnafter=" + wait;
                parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
            }

            string address  = "http://" + Host + ":4380/" + request + parameters;
            string response = "";

            try
            {
                using (var wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                    {
                        response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)) + " ]";
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(response);
        }
コード例 #2
0
        internal string Query(string request, bool oauth, bool cfid, int wait)
        {
            string parameters = "?&ref=&cors=&_=" + GetTimestamp();

            if (request.Contains("?"))
            {
                parameters = parameters.Substring(1);
            }

            if (oauth)
            {
                parameters += "&oauth=" + OauthKey;
            }
            if (cfid)
            {
                parameters += "&csrf=" + CfidKey;
            }

            if (wait != -1)
            {
                parameters += "&returnafter=" + wait;
                parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
            }

            string address  = $"{_config.HostUrl}:{_config.Port}/{request}{parameters}";
            string response = "";

            try
            {
                using (var wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                    {
                        response = "[ " + wc.DownloadString(address) + " ]";
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(response);
        }
コード例 #3
0
        internal async Task <string> QueryAsync(string baseUrl, bool oauth, bool cfid, int wait, NameValueCollection @params = null)
        {
            string parameters = BuildQueryString(oauth, cfid, wait, @params);
            string address    = $"{_config.HostUrl}:{_config.Port}/{baseUrl}?{parameters}";
            string response   = "";

            try
            {
                using (ExtendedWebClient wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                    {
                        response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)).ConfigureAwait(false) + " ]";
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(response);
        }