Exemplo n.º 1
0
    public void doPost(PostParamCollection postParamCollection)
    {
        try
        {
            Uri        uri        = new Uri(this.PostUri);
            WebRequest webRequest = WebRequest.Create(uri);
            webRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, this.Language);

            if (this.Proxy != null)
            {
                webRequest.Proxy = Proxy;
            }

            webRequest.Method      = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";

            string parameterString = "";

            foreach (PostParam parameter in postParamCollection)
            {
                parameterString += parameter.Paramter + "=" + parameter.Value + "&";
            }

            parameterString = parameterString.Substring(0, parameterString.Length - 1);

            byte[] byteArray = Encoding.UTF8.GetBytes(parameterString);
            webRequest.ContentLength = byteArray.Length;

            Stream stream = webRequest.GetRequestStream();
            stream.Write(byteArray, 0, byteArray.Length);
            stream.Close();

            WebResponse webResponse = webRequest.GetResponse();
            stream = webResponse.GetResponseStream();

            StreamReader streamReader   = new StreamReader(stream);
            string       responseStream = streamReader.ReadToEnd();

            webResponse.Close();
            streamReader.Close();

            if (PostComplete != null)
            {
                PostComplete.Invoke(responseStream, null);
            }
        }
        catch (Exception exception)
        {
            throw exception;
        }
    }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length >= 2)
            {
                string hostname = args[0];

                PostParamCollection postParamCollection = new PostParamCollection();
                List <string>       getCollection       = new List <string>();

                for (int i = 1; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "powerOn":
                        postParamCollection.Add(new PostParam("cmd0", "PutZone_OnOff/ON"));
                        break;

                    case "powerOff":
                        postParamCollection.Add(new PostParam("cmd0", "PutZone_OnOff/OFF"));
                        break;

                    case "power":
                        postParamCollection.Add(switchPower(hostname));
                        break;

                    case "muteOn":
                        postParamCollection.Add(new PostParam("cmd0", "PutVolumeMute/on"));
                        break;

                    case "muteOff":
                        postParamCollection.Add(new PostParam("cmd0", "PutVolumeMute/off"));
                        break;

                    case "mute":
                        postParamCollection.Add(switchMute(hostname));
                        break;

                    case "volUp":
                        postParamCollection.Add(new PostParam("cmd0", "PutMasterVolumeBtn/>"));
                        break;

                    case "volDown":
                        postParamCollection.Add(new PostParam("cmd0", "PutMasterVolumeBtn/<"));
                        break;

                    case "inputTuner":
                        postParamCollection.Add(new PostParam("cmd0", "PutZone_InputFunction/TUNER"));
                        break;

                    case "tunerPresetUp":
                        getCollection.Add("/goform/formiPhoneAppTuner.xml?1+PRESETUP");
                        break;

                    case "tunerPresetDown":
                        getCollection.Add("/goform/formiPhoneAppTuner.xml?1+PRESETDOWN");
                        break;

                    case "netPlayPause":
                        postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurEnter"));
                        break;

                    case "netNextTrack":
                        postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurDown"));
                        break;

                    case "netPrevTrack":
                        postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurUp"));
                        break;

                    default:
                        break;
                    }
                }
                try
                {
                    if (postParamCollection.Count > 0)
                    {
                        HttpPost httpPost = new HttpPost("http://" + hostname + "/MainZone/index.put.asp");
                        foreach (PostParam param in postParamCollection)
                        {
                            httpPost.doPost(param);
                        }
                    }
                    if (getCollection.Count > 0)
                    {
                        WebRequest wrGETURL;
                        foreach (string call in getCollection)
                        {
                            wrGETURL = WebRequest.Create("http://" + hostname + call);
                            wrGETURL.GetResponse();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("[DenonCMD] " + ex.Message);
                }
            }
            else
            {
                Debug.WriteLine("[DenonCMD] " + "I need two or more arguments arguments: host command [command...]");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length >= 2)
            {
                string hostname = args[0];

                PostParamCollection postParamCollection = new PostParamCollection();
                List<string> getCollection = new List<string>();

                for (int i = 1; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                        case "powerOn":
                            postParamCollection.Add(new PostParam("cmd0", "PutZone_OnOff/ON"));
                            break;
                        case "powerOff":
                            postParamCollection.Add(new PostParam("cmd0", "PutZone_OnOff/OFF"));
                            break;
                        case "power":
                            postParamCollection.Add(switchPower(hostname));
                            break;

                        case "muteOn":
                            postParamCollection.Add(new PostParam("cmd0", "PutVolumeMute/on"));
                            break;
                        case "muteOff":
                            postParamCollection.Add(new PostParam("cmd0", "PutVolumeMute/off"));
                            break;
                        case "mute":
                            postParamCollection.Add(switchMute(hostname));
                            break;

                        case "volUp":
                            postParamCollection.Add(new PostParam("cmd0", "PutMasterVolumeBtn/>"));
                            break;
                        case "volDown":
                            postParamCollection.Add(new PostParam("cmd0", "PutMasterVolumeBtn/<"));
                            break;

                        case "inputTuner":
                            postParamCollection.Add(new PostParam("cmd0", "PutZone_InputFunction/TUNER"));
                            break;
                        case "tunerPresetUp":
                            getCollection.Add("/goform/formiPhoneAppTuner.xml?1+PRESETUP");
                            break;
                        case "tunerPresetDown":
                            getCollection.Add("/goform/formiPhoneAppTuner.xml?1+PRESETDOWN");
                            break;

                        case "netPlayPause":
                            postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurEnter"));
                            break;
                        case "netNextTrack":
                            postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurDown"));
                            break;
                        case "netPrevTrack":
                            postParamCollection.Add(new PostParam("cmd0", "PutNetAudioCommand/CurUp"));
                            break;

                        default:
                            break;
                    }
                }
                try
                {
                    if (postParamCollection.Count > 0)
                    {
                        HttpPost httpPost = new HttpPost("http://" + hostname + "/MainZone/index.put.asp");
                        foreach (PostParam param in postParamCollection)
                        {
                            httpPost.doPost(param);
                        }

                    }
                    if (getCollection.Count > 0)
                    {
                        WebRequest wrGETURL;
                        foreach (string call in getCollection)
                        {
                            wrGETURL = WebRequest.Create("http://" + hostname + call);
                            wrGETURL.GetResponse();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("[DenonCMD] " + ex.Message);
                }
            }
            else
            {
                Debug.WriteLine("[DenonCMD] " + "I need two or more arguments arguments: host command [command...]");
            }
        }