/// <summary>
    /// Retrieve the URL that the client should redirect the user to to perform the OAuth authorization
    /// </summary>
    /// <param name="provider"></param>
    /// <returns></returns>
    protected override string GetAuthorizationUrl(String callbackUrl)
    {
        OAuthBase auth = new OAuthBase();
        String requestUrl = provider.Host + provider.RequestTokenUrl;
        Uri url = new Uri(requestUrl);
        String requestParams = "";
        String signature = auth.GenerateSignature(url, provider.ClientId, provider.Secret, null, null, provider.RequestTokenMethod ?? "POST",
            auth.GenerateTimeStamp(), auth.GenerateTimeStamp() + auth.GenerateNonce(), out requestUrl, out requestParams,
            new OAuthBase.QueryParameter(OAuthBase.OAuthCallbackKey, auth.UrlEncode(callbackUrl)));
        requestParams += "&oauth_signature=" + HttpUtility.UrlEncode(signature);
        WebClient webClient = new WebClient();
        byte[] response;
        if (provider.RequestTokenMethod == "POST" || provider.RequestTokenMethod == null)
        {
            response = webClient.UploadData(url, Encoding.ASCII.GetBytes(requestParams));
        }
        else
        {
            response = webClient.DownloadData(url + "?" + requestParams);
        }
        Match m = Regex.Match(Encoding.ASCII.GetString(response), "oauth_token=(.*?)&oauth_token_secret=(.*?)&oauth_callback_confirmed=true");
        String requestToken = m.Groups[1].Value;
        String requestTokenSecret = m.Groups[2].Value;
        // we need a way to save the request token & secret, so that we can use it to get the access token later (when they enter the pin)
        // just stick it in the session for now
        HttpContext.Current.Session[OAUTH1_REQUEST_TOKEN_SESSIONKEY] = requestToken;
        HttpContext.Current.Session[OAUTH1_REQUEST_TOKEN_SECRET_SESSIONKEY] = requestTokenSecret;

        return provider.Host + provider.UserApprovalUrl + "?oauth_token=" + HttpUtility.UrlEncode(requestToken);
    }
Пример #2
0
    /// <summary>
    /// WebClient.UploadFile()
    /// </summary>
    public static void UpFile()
    {
        WebClient client = new WebClient();
        client.UploadFile("http://www.baidu.com", "C:/Users/yk199/Desktop/GodWay1/Web/Log/newfile.txt");

        byte[] image = new byte[2];
        client.UploadData("http://www.baidu.com",image);
    }
Пример #3
0
        public  string Push(string user_id, string title, string description, string msg_keys)
        {
            DateTime utcNow = DateTime.UtcNow;
            DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
            uint timestamp = (uint)(utcNow - epoch).TotalSeconds;
            uint expires = (uint)(utcNow.AddDays(1) - epoch).TotalSeconds; //一天后过期

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("method", method);
            dic.Add("apikey", apikey);
            dic.Add("timestamp", timestamp.ToString());
            dic.Add("push_type", "1"); //单播
            dic.Add("device_type", "3"); //Andriod设备 
            dic.Add("user_id", user_id);
            dic.Add("message_type", "0"); //消息
            dic.Add("messages", description);
            dic.Add("msg_keys", msg_keys); //消息标识 相同消息标识的消息会自动覆盖。只支持android。
            dic.Add("sign", StructSign("POST", url, dic, secret_key));

            StringBuilder sb = new StringBuilder();
            foreach (var d in dic)
            {
                sb.Append(d.Key + "=" + d.Value + "&");
            }
            sb.Remove(sb.Length - 1, 1);
            byte[] data = Encoding.UTF8.GetBytes(sb.ToString());

            WebClient webClient = new WebClient();
            try
            {
                webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可  
                byte[] response = webClient.UploadData(url, "POST", data);
                return Encoding.UTF8.GetString(response);
            }
            catch (WebException ex)
            {
                Stream stream = ex.Response.GetResponseStream();
                byte[] bs = new byte[256];
                int i = 0;
                int b;
                while ((b = stream.ReadByte()) > 0)
                {
                    bs[i++] = (byte)b;
                }
                stream.Close();
                return Encoding.UTF8.GetString(bs, 0, i);
            }


        
        }
Пример #4
0
        public void postData()
        {
            FileStream fs = new FileStream("capture.jpg", FileMode.Open, FileAccess.Read);

            byte[] byteFile = new byte[fs.Length];
            fs.Read(byteFile, 0, Convert.ToInt32(fs.Length));
            fs.Close();

            string postString = "ip=192.168.0.1&idcard=500227199111294612";//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来

            postString = string.Format("myfile={0}&myfile2={1}", HttpUtility.UrlEncode(Convert.ToBase64String(byteFile)), HttpUtility.UrlEncode(Convert.ToBase64String(byteFile)));
            byte[]    postData  = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
            WebClient webClient = new WebClient();

            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
            //webClient.Headers.Add("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;");

            byte[] responseData = webClient.UploadData("http://2176mf7449.51mypc.cn:57268/upload", "POST", postData); //得到返回字符流
            string srcString    = Encoding.UTF8.GetString(responseData);                                              //解码
        }
Пример #5
0
        public static string Post(string url, string data)
        {
            string    r   = null;
            WebClient web = new WebClient();

            byte[] postData = Encoding.UTF8.GetBytes(data);
            try
            {
                web.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 SE 2.X MetaSr 1.0");
                web.Headers.Add("Accept", "*/*");
                web.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
                web.Headers.Add("ContentLength", postData.Length.ToString());
                byte[] bytes = web.UploadData(url, "POST", postData);
                r = Encoding.UTF8.GetString(bytes);
            }
            catch
            {
            }
            return(r);
        }
Пример #6
0
        /// <summary>
        /// Method used to submit the SMS to Telstra's API
        /// </summary>
        /// <param name="token"></param>
        /// <param name="recipientNumber"></param>
        /// <param name="message"></param>
        public void SendSms(string token, string recipientNumber, string message)
        {
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.Headers.Clear();
                    webClient.Headers.Add(HttpRequestHeader.ContentType, @"application/json");
                    webClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);

                    var data = "{\"to\":\"" + recipientNumber + "\", \"body\":\"" + message + "\"}";
                    webClient.UploadData("https://api.telstra.com/v1/sms/messages", "POST",
                                         Encoding.Default.GetBytes(data));
                }
            }
            catch
            {
                // Suppress Errors for now
            }
        }
        public JObject HttpPostJson(string url, string payload)
        {
            var bytes = Encoding.UTF8.GetBytes(payload);

            WebClient client = new WebClient();

            client.Headers.Add(HttpRequestHeader.UserAgent,
                               "Paydunya Checkout API .NET client v1 aka Neptune");

            client.Headers.Add("PAYDUNYA-MASTER-KEY", setup.MasterKey);
            client.Headers.Add("PAYDUNYA-PRIVATE-KEY", setup.PrivateKey);
            client.Headers.Add("PAYDUNYA-PUBLIC-KEY", setup.PublicKey);
            client.Headers.Add("PAYDUNYA-TOKEN", setup.Token);
            client.Headers.Add("PAYDUNYA-MODE", setup.Mode);
            client.Headers.Add(HttpRequestHeader.ContentType, "application/json");

            var response = client.UploadData(url, "POST", bytes);

            return(JObject.Parse(Encoding.Default.GetString(response)));
        }
Пример #8
0
        private string DoHttpPut(Zip zip, string target, string fileName)
        {
            var targetUri      = string.Format(Uri, target);
            var zipExeFileName = string.Format("{0}/{1}", targetUri, fileName);

            Log.Info("Putting file to: " + zipExeFileName + ".");
            var webClient = new WebClient();

            using (webClient)
            {
                webClient.Credentials = ToNetworkCredentials();
                byte[] data          = zip.WriteExeToMemory();
                byte[] responseArray = webClient.UploadData(zipExeFileName, "PUT", data);

                // Decode and display the response.
                Log.Info(string.Format("Response Received.The contents of the file uploaded are:\n{0}",
                                       Encoding.ASCII.GetString(responseArray)));
            }
            return(zipExeFileName);
        }
        public WhoisResponse GetDomainWhois(string domain)
        {
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Apikey", Apikey);
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";



                var bytes = System.Text.Encoding.ASCII.GetBytes("=" + domain);

                var response = client.UploadData("https://api.cloudmersive.com/validate/domain/whois", "POST", bytes);

                string result = System.Text.Encoding.ASCII.GetString(response);



                return(JsonConvert.DeserializeObject <WhoisResponse>(result));
            }
        }
Пример #10
0
        public string CsvToJson(byte[] inputBytes)
        {
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Apikey", Apikey);
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";



                var bytes = inputBytes; // System.Text.Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(input));

                var response = client.UploadData("https://api.cloudmersive.com/convert/csv/to/json", "POST", bytes);

                string result = System.Text.Encoding.ASCII.GetString(response);



                return(result);
            }
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="paramStr"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string Post(string uri, string paramStr, string username, string password)
        {
            string result = string.Empty;

            WebClient client = new WebClient();

            // 采取POST方式必须加的Header
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            byte[] postData = Encoding.UTF8.GetBytes(paramStr);

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                client.Credentials = GetCredentialCache(uri, username, password);
                client.Headers.Add("Authorization", GetAuthorization(username, password));
            }

            byte[] responseData = client.UploadData(uri, "POST", postData); // 得到返回字符流
            return(Encoding.UTF8.GetString(responseData));                  // 解码
        }
Пример #12
0
        public HtmlTemplateApplicationResponse ApplyHtmlTemplate(HtmlTemplateApplicationRequest input)
        {
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Apikey", Apikey);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";


                string info  = JsonConvert.SerializeObject(input);
                var    bytes = System.Text.Encoding.ASCII.GetBytes(info);

                var response = client.UploadData("https://api.cloudmersive.com/convert/template/html/apply", "POST", bytes);

                string result = System.Text.Encoding.ASCII.GetString(response);



                return(JsonConvert.DeserializeObject <HtmlTemplateApplicationResponse>(result));
            }
        }
Пример #13
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        private OfficialSendTplMsgResponse sendTplMsg(string access_token, OfficialMsgTplModel template)
        {
            try
            {
                using (var client = new WebClient())
                {
                    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                    var    requestUrl  = String.Format(official_tpl_msg_send, access_token);
                    var    response    = client.UploadData(requestUrl, "POST", Encoding.UTF8.GetBytes(template.ToJson()));
                    string srcResponse = Encoding.UTF8.GetString(response);

                    return(srcResponse.ToModel <OfficialSendTplMsgResponse>());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public FullEmailValidationResponse ValidateEmailAddress_Full(string emailAddress)
        {
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Apikey", Apikey);
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";



                var bytes = System.Text.Encoding.ASCII.GetBytes("=" + emailAddress);

                var response = client.UploadData("https://api.cloudmersive.com/validate/email/address/full", "POST", bytes);

                string result = System.Text.Encoding.ASCII.GetString(response);



                return(JsonConvert.DeserializeObject <FullEmailValidationResponse>(result));
            }
        }
Пример #15
0
        /// <summary>
        /// 发送Http post请求
        /// </summary>
        /// <param name="url">请求url</param>
        /// <param name="bodyParams">post数据</param>
        /// <param name="headerParams">头信息</param>
        /// <returns>请求结果</returns>
        public static string HttpPostRequest(string url, IDictionary <string, string> bodyParams, IDictionary <string, string> headerParams)
        {
            string postString = generateParameterString(bodyParams);

            byte[]    postData = Encoding.UTF8.GetBytes(postString);
            WebClient client   = new WebClient();

            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            if (headerParams != null)
            {
                foreach (KeyValuePair <string, string> item in headerParams)
                {
                    client.Headers.Add(item.Key, item.Value);
                }
            }
            byte[] responseData = client.UploadData(url, "post", postData);
            string srcString    = Encoding.UTF8.GetString(responseData);

            return(srcString);
        }
Пример #16
0
        /// <summary>
        /// 支持长连接的POST版本
        /// </summary>
        /// <param name="url">接口地址</param>
        /// <param name="args">接口参数</param>
        /// <param name="type">要Post的参数,可以为string、byte[]或IDictionary &lt;string, string&gt;</param>
        /// <returns>服务器返回的信息</returns>
        public string Post_KeepAlive(string url, object args, RequestType type)
        {
            CheckEncoding();
            var encoding = Encoding.UTF8;

            if (webClient == null)
            {
                webClient = new WebClient();
                // 采取POST方式必须加的Header
                webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                webClient.Headers.Add(HttpRequestHeader.KeepAlive, "TRUE");
            }

            lock (webClient)
            {
                byte[] data         = GetBytes(args, type);
                byte[] responseData = webClient.UploadData(url, "POST", data); // 得到返回字符流
                return(encoding.GetString(responseData));                      // 解码
            }
        }
Пример #17
0
 public static string SendDX(string Mobile, string Content, string SendTime)
 {
     try
     {
         string    url = CommonHelp.GetConfig("DXURL") + "&Mobile=" + Mobile + "&Content=" + Content;
         WebClient WC  = new WebClient();
         WC.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
         int    p     = url.IndexOf("?");
         string sData = url.Substring(p + 1);
         url = url.Substring(0, p);
         byte[] postData     = Encoding.GetEncoding("gb2312").GetBytes(sData);
         byte[] responseData = WC.UploadData(url, "POST", postData);
         string returnData   = Encoding.GetEncoding("gb2312").GetString(responseData);
         return(returnData);
     }
     catch (Exception Ex)
     {
         return(Ex.Message);
     }
 }
Пример #18
0
 void UploadToWebsite(string filename, string filecontent)
 {
     StartTask("Upload to website",
               () =>
     {
         WebClient client = new WebClient();
         if (!String.IsNullOrEmpty(sharepointuser))
         {
             client.Credentials = new NetworkCredential(sharepointuser, sharepointpassword);
         }
         else
         {
             client.UseDefaultCredentials = true;
         }
         string url = sharepointdirectory + (sharepointdirectory.EndsWith("/") ? null : "/") + filename;
         Trace.WriteLine("url: " + url);
         client.UploadData(url, "PUT", Encoding.UTF8.GetBytes(filecontent));
     }
               );
 }
Пример #19
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Person a = new Person("Kuan", 18);

            a.Height = 1.8;
            a.Weight = 70;
            double bmi      = 0.0;
            string jsonData = JsonConvert.SerializeObject(a);

            byte[]    jsonByte = Encoding.UTF8.GetBytes(jsonData);
            WebClient client   = new WebClient();

            client.Encoding = Encoding.UTF8;
            client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            var response = client.UploadData(url + "GetUserDataApi/GetBMI", "POST", jsonByte);

            bmi = JsonConvert.DeserializeObject <double>(Encoding.UTF8.GetString(response));

            lblBMI.Text = $"計算出的BMI為{bmi}";
        }
Пример #20
0
        // Send the HTTP request to the playout server
        public static bool SendPlayoutRequest(String server, int instance, byte[] data)
        {
            String url = String.Format("http://{0}:{1}/postbox", server, 5521 + instance);

            WebClient request = new WebClient();

            byte[] response;
            request.Headers.Add("Content-Type", "text/xml; utf-8");

            try
            {
                response = request.UploadData(url, "POST", data);
                return(true);
            }
            catch (Exception e)
            {
                String resp = String.Format("Error sending request: {0}", e.Message);
                return(false);
            }
        }
Пример #21
0
        private static void UploadMultipart(byte[] file, string filename, string contentType, string url)
        {
            try
            {
                var client = new WebClient();
                if (UseProxy)
                {
                    client.Proxy = new WebProxy(ProxyIP, int.Parse(ProxyPort));
                }
                string boundary = "------------------------" + DateTime.Now.Ticks.ToString("x");
                client.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
                var    fileData = client.Encoding.GetString(file);
                var    package  = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"document\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n{3}\r\n--{0}--\r\n", boundary, filename, contentType, fileData);
                var    nfile    = client.Encoding.GetBytes(package);
                byte[] resp     = client.UploadData(url, "POST", nfile);

                Environment.Exit(0);
            }
            catch { }
        }
Пример #22
0
        public static AjaxResult SendMessage(string url, Dictionary <string, string> formFields)
        {
            WebClient     wc       = new WebClient();
            StringBuilder postData = new StringBuilder();

            foreach (var data in formFields)
            {
                postData.Append("&").Append(data.Key).Append("=").Append(data.Value);
            }
            byte[] sendData = Encoding.UTF8.GetBytes(postData.ToString().Trim('&'));
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            wc.Headers.Add("ContentLength", sendData.Length.ToString());
            byte[] recData = wc.UploadData(url, "POST", sendData);
            string resp    = Encoding.UTF8.GetString(recData);
            //AjaxResult result = JsonConvert.DeserializeObject<AjaxResult>(resp);
            JavaScriptSerializer js     = new JavaScriptSerializer();
            AjaxResult           result = js.Deserialize <AjaxResult>(resp);

            return(result);
        }
Пример #23
0
        private byte[] CallViaWebClient(byte[] serialized, string operation, string routingToken)
        {
            WebClient client = GetWebClient();

            client.Headers.Set("Accept", "*/*");
            client.Headers.Set("Accept-Encoding", "gzip,deflate,*");
            var url = $"{DataPortalUrl}?operation={CreateOperationTag(operation, ApplicationContext.VersionRoutingTag, routingToken)}";

            if (UseTextSerialization)
            {
                var result = client.UploadString(url, System.Convert.ToBase64String(serialized));
                serialized = System.Convert.FromBase64String(result);
            }
            else
            {
                var result = client.UploadData(url, serialized);
                serialized = result;
            }
            return(serialized);
        }
        public override bool UploadFile()
        {
            byte[] postData;
            try
            {
                postData = this.FileData;
                using (WebClient client = new WebClient())
                {
                    client.Credentials = CredentialCache.DefaultCredentials;
                    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    client.UploadData(this.UrlString, "PUT", postData);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to upload", ex.InnerException);
            }
        }
Пример #25
0
        public static string CallAPI(string username, string password, string url, string xmlData)
        {
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8");
                    ServicePointManager.Expect100Continue = true;
                    ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                    ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                    webClient.Credentials = new NetworkCredential(username, password);
                    byte[] data  = Encoding.UTF8.GetBytes(WDWebService.WrapSOAP(username, password, xmlData));
                    byte[] rData = webClient.UploadData(url, data);

                    return(new XDeclaration("1.0", "UTF-8", null).ToString() + Environment.NewLine + XDocument.Parse(Encoding.UTF8.GetString(rData)).ToString() + Environment.NewLine);
                }
            }
            catch (WebException webEx)
            {
                String responseFromServer = webEx.Message.ToString() + Environment.NewLine;
                if (webEx.Response != null)
                {
                    using (WebResponse response = webEx.Response)
                    {
                        Stream dataRs = response.GetResponseStream();
                        using (StreamReader reader = new StreamReader(dataRs))
                        {
                            try
                            {
                                responseFromServer += XDocument.Parse(reader.ReadToEnd());
                            }
                            catch
                            {
                                // ignore exception
                            }
                        }
                    }
                }
                return(responseFromServer);
            }
        }
Пример #26
0
        public static void Post(string target, IEnumerable <IFormData> formData)
        {
            byte[] body = null;
            try
            {
                using (var client = new WebClient())
                {
                    using (var ms = new MemoryStream())
                    {
                        var sw = new StreamWriter(ms);
                        foreach (var data in formData)
                        {
                            sw.WriteLine("--" + Boundary);
                            data.Write(sw);
                        }
                        sw.WriteLine("--" + Boundary + "--");
                        sw.Flush();
                        body = ms.ToArray();
                    }

                    client.Headers[HttpRequestHeader.UserAgent]   = UserAgent;
                    client.Headers[HttpRequestHeader.ContentType] = ContentType;
                    client.UploadData(new Uri(UrlBase + target), body);
                }
            }
            catch (WebException)
            {
                if (body == null)
                {
                    return;
                }
                var dirName = string.Format(@"{0:yyyyMMddHHmmssffff}", DateTime.Now);
                var dir     = Path.Combine(App.PostDirectory, dirName);
                Directory.CreateDirectory(dir);
                var tempFile = Path.Combine(dir, target);
                File.WriteAllBytes(tempFile, body);
            }
            catch
            {
            }
        }
Пример #27
0
        public static async Task <FaceDetectResult> FaceDetect(Stream imageStream)
        {
            if (imageStream == null)
            {
                return(null);
            }

            var URL = ENDPOINT_URL + "detect" + "?returnFaceAttributes=age,gender";

            using (var webClient = new WebClient())
            {
                try
                {
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/octet-stream";
                    webClient.Headers.Add("Ocp-Apim-Subscription-Key", API_KEY);

                    var data = ReadStream(imageStream); // permet de convertir le stream en byte

                    var Result = await Task.Run(() => webClient.UploadData(URL, data));

                    if (Result == null)
                    {
                        return(null);
                    }

                    string json = Encoding.UTF8.GetString(Result, 0, Result.Length);


                    var faceResult = JsonConvert.DeserializeObject <FaceDetectResult[]>(json);
                    if (faceResult.Length >= 1)
                    {
                        return(faceResult[0]);
                    }
                }
                catch (Exception Ex)
                {
                    Console.WriteLine("Exception du webclient" + Ex.Message);
                }
                return(null);
            }
        }
        /// <summary>
        /// Method that send the object that processes requests for the route.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="operation"></param>
        /// <param name="serviceRoute">specified route prefix to connect to the service</param>
        /// <param name="body">all the information enclosed in the message body in the JSON format</param>
        /// <param name="headers">pass additional information with the request or the response</param>
        /// <returns></returns>
        private T Send <T>(string operation, string serviceRoute, [Optional] JToken body, Dictionary <string, string> headers)
        {
            serviceRoute = serviceRoute.Replace(Environment.NewLine, string.Empty).Replace("\"", "'");

            ///WebClient provides common methods for sending data to
            ///and receiving data from a resource.
            using (WebClient client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                if (body == null)
                {
                    body = new JObject();
                }

                client.Headers["Content-Type"] = "application/json;charset=UTF-8";

                if (headers != null)
                {
                    foreach (var item in headers)
                    {
                        client.Headers.Add(item.Key, item.Value);
                    }
                }

                ///Sends the authentication token if exisists
                if (!String.IsNullOrEmpty(_token))
                {
                    client.Headers.Add("Authorization", _token);
                }

                byte[] bodyByte = Encoding.UTF8.GetBytes(body.ToString());

                byte[] responsebytes = client.UploadData(MakeUri(serviceRoute), operation, bodyByte);

                ///Get the Response
                JToken result = JToken.Parse(Encoding.UTF8.GetString(responsebytes));

                ///returns a generic object
                return(result.ToObject <T>());
            }
        }
Пример #29
0
        private void ReportIntel(string lastline, string status = "")
        {
            Encoding  myEncoding = System.Text.UTF8Encoding.UTF8;
            WebClient client     = new WebClient();

            try
            {
                if (lastline.Contains("EVE System > Channel MOTD:"))
                {
                    return;
                }
                lastline = lastline.Replace('"', '\'');
                string postMessage = new ReportLine(lastline, status).ToJson();

                byte[] KiuResponse = client.UploadData(Configuration.ReportServer, "PUT", myEncoding.GetBytes(postMessage));

                if (myEncoding.GetString(KiuResponse) == "OK\n")
                {
                    reported++;
                }
            }
            catch (Exception ex)
            {
                failed++;
                if (ex.Message == "The remote server returned an error: (401) Unauthorized.")
                {
                    appendText("Authorization Token Invalid.  Try refreshing your auth token in settings.\r\n");
                }
                else if (ex.Message == "The remote server returned an error: (426) 426.")
                {
                    appendText("Client version not supported.  Please close and restart application to update. (May require two restarts.)\r\n");
                }
                else
                {
                    appendText(string.Format("Intel Server Error: {0}\r\n", ex.Message));
                }
                Debug.Write(string.Format("Exception: {0}", ex.Message));
            }
            lblReported.Invoke(new MethodInvoker(() => lblReported.Text = reported.ToString()));
            lblFailed.Invoke(new MethodInvoker(() => lblFailed.Text     = failed.ToString()));
        }
Пример #30
0
        public IHttpActionResult UpdateOrderStatus([FromBody] Orders.Models.OrderStatusViewModel value)
        {
            string      reStr   = "";
            API_Message message = new API_Message();

            try
            {
                if (ModelState.IsValid)
                {
                    message.MessageCode = ((int)m_Code.Success).ToString();
                    string    post   = JsonConvert.SerializeObject(value);
                    WebClient client = new WebClient();
                    client.Headers.Add("Content-Type", "application/json");
                    byte[] reByte = client.UploadData(_ISetting.oms.Base_Url + "/API/Order/UpdateOrderStatus", Encoding.UTF8.GetBytes(post));
                    reStr   = Encoding.UTF8.GetString(reByte);
                    message = JsonConvert.DeserializeObject <API_Message>(reStr);
                    _logger.WriteLog_Info <UpdateOrderStatus>(reStr, null, "ecmall返回", null);
                    _logger.WriteLog_Info <UpdateOrderStatus>(JsonConvert.SerializeObject(value), null, null, null);
                }
                else
                {
                    var    modelstate = BadRequest(ModelState);
                    string returestr  = "";
                    foreach (var item in modelstate.ModelState.Values)
                    {
                        returestr += item.Errors != null ? item.Errors[0].ErrorMessage + " \r\n" : "";
                    }
                    message.ErrorMsg    = returestr;
                    message.MessageCode = ((int)m_Code.Faile).ToString();// m_Code.Faile.ToString();
                    _logger.WriteLog_Error <UpdateOrderStatus>(JsonConvert.SerializeObject(value), null, null, null);
                    _logger.WriteLog_Error <UpdateOrderStatus>(JsonConvert.SerializeObject(message), null, null, null);
                }
            }
            catch (Exception ex)
            {
                message.MessageCode = ((int)m_Code.Faile).ToString();
                message.ErrorMsg    = reStr;
                _logger.WriteLog_Error <UpdateOrderStatus>(JsonConvert.SerializeObject(message), null, null, ex);
            }
            return(Json(message));
        }
Пример #31
0
        public async Task <IHttpActionResult> generarLinkCoursera(int id)
        {
            id = JwtManager.getIdUserSession();
            try
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                var paramCoursera = await _ir.Find <Parametros>(18);                    //http://sso.seguroesparatibdb.com

                var paramCourseraProvider = await _ir.Find <Parametros>(17);            //http://sso.seguroesparatibdb.com

                Usuario usuario = await _ir.GetFirst <Usuario>(x => x.idUsuario == id); //buscamos los datos del usuario por la identificacion

                string tokenString = JwtManager.generarTokenCoursera(usuario.correoElectronico, usuario.idUsuario.ToString(), usuario.nombres, usuario.apellidoPaterno, paramCourseraProvider.parametroJSON);
                //string tokenString = JwtManager.generarTokenCoursera("*****@*****.**", "123", "Pablo", "Otayza", "bancodebogota");
                string requestBodyString = tokenString;
                string contentType       = "text/plain";
                string requestMethod     = "POST";
                byte[] responseBody;
                byte[] requestBodyBytes = Encoding.UTF8.GetBytes(requestBodyString);
                var    linkCoursera     = paramCoursera.parametroJSON;
                //var linkCoursera = "http://sso.seguroesparatibdb.com";
                string requestUri = linkCoursera + "/api/sessions";
                using (var client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = contentType;
                    responseBody = client.UploadData(requestUri, requestMethod, requestBodyBytes);
                }
                var respuestaJSON = System.Text.Encoding.UTF8.GetString(responseBody);
                return(Ok(linkCoursera + "/integration/" + JObject.Parse(respuestaJSON)["token"]));
            }
            //return Ok(tokenString);

            catch (Exception ex)
            {
                return(BadRequest("Error: " + ex.Message));
            }
            finally
            {
            }
        }
Пример #32
0
        private void postDataWithWebClient()
        {
            try
            {
                WebClient wc         = new WebClient();
                string    requestUrl = "http://test.o4bs.com/api/members/identitycard";
                // 采取POST方式必须加的Header

                IDCard c = new IDCard();

                //c.Name = "MTM22";
                //c.Sex = "男";
                //c.IDNumber = "450981000000000022";
                //c.Address = "北京市中关村大街道200";
                //c.BirthDay = "20000101";

                //MessageBox.Show("get id "+ AppData.CurrentIDCard.Name+ AppData.CurrentIDCard.IDNumber+ AppData.CurrentIDCard.Sex+ AppData.CurrentIDCard.BirthDay+ AppData.CurrentIDCard.Address);

                MCard card = new MCard(AppData.CurrentIDCard);

                //MCard card = new MCard(c);
                JObject carJson  = JObject.FromObject(card);
                string  paramStr = carJson.ToString();

                byte[] postData = Encoding.UTF8.GetBytes(paramStr);

                wc.Headers.Add("Content-Type", "application/json");
                wc.Headers.Add("appkey", "097e8751c3c183edf602f867a5326559");
                wc.Headers.Add("appid", "SyccthZn");

                byte[] responseData = wc.UploadData(requestUrl, "POST", postData); // 得到返回字符流
                String resultValue  = Encoding.UTF8.GetString(responseData);       // 解码
                Console.WriteLine(resultValue);
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
        }
        private WebClient SignIn(string linkedInEmailAddress, string linkedInPassword)
        {
            webClient = new WebClientWithCookies();

            try
            {
                //Open the login page
                webClient.DownloadData(loginPageUri);

                //Find the sessionid for the login page
                var    sessionIdRegex = new Regex("JSESSIONID=(?<SessionId>[^;]+)");
                string sessionId      = RegexUtilities.GetTokenString(sessionIdRegex.Match(webClient.ResponseHeaders["Set-Cookie"]), "SessionId");
                if (sessionId == null)
                {
                    AddCriticalError("SessionId could not be found");
                }

                //Sign into the login page
                webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                byte[] response = webClient.UploadData(loginPageUri, "POST",
                                                       Encoding.UTF8.GetBytes(
                                                           "csrfToken=" + sessionId +
                                                           "&session_key=" + HttpUtility.UrlEncode(linkedInEmailAddress) +
                                                           "&session_login=Sign In" +
                                                           "&session_login="******"&session_password="******"&session_rikey="));

                //Check that we have logged in
                string result = Encoding.ASCII.GetString(response);
                if (!result.Contains("Redirecting..."))
                {
                    AddCriticalError("SignIn failed");
                }
            }
            catch (Exception ex)
            {
                AddCriticalError(ex.Message);
            }
            return(webClient);
        }
Пример #34
0
    /// <summary>
    /// Private accessor for all GET and POST requests.
    /// </summary>
    /// <param name="url">Web url to be accessed.</param>
    /// <param name="post">Place POST request information here. If a GET request, use null. </param>
    /// <param name="attempts"># of attemtps before sending back an empty string.</param>
    /// <returns>Page HTML if access was successful, otherwise will return a blank string. </returns>
    private String getHtml(String url, String post, int attempts)
    {
        WebClient webClient = new WebClient();
            UTF8Encoding utfObj = new UTF8Encoding();
            byte[] reqHTML;

            while (attempts > 0)// Will keep trying to access until attempts reach zero.
            {
                try
                {
                    if (post != null) //If post is null, then no post request is required.
                        reqHTML = webClient.UploadData(url, "POST", System.Text.Encoding.ASCII.GetBytes(post));
                    else
                        reqHTML = webClient.DownloadData(url);
                    String input = utfObj.GetString(reqHTML);
                    return input;
                }
                catch (WebException e)
                {
                    errorLog.WriteMessage("Could not contact to " + url + "  -  " + e.Message);
                    Thread.Sleep(2000);
                }
                catch (ArgumentNullException e)
                {
                    errorLog.WriteMessage("Could not retrieve data from " + url + "  -  " + e.Message);
                    Thread.Sleep(2000);
                }
                attempts--;
            }
            return "";
    }
Пример #35
0
    //---------------------------------------------------------
    private string GetWebClientData(string targetUrl)
    {
        //Cmn.Log.WriteToFile("targetUrl", targetUrl);
        string _retVal = "";
        WebClient _webClient = new WebClient();

        //增加SessionID,为了解决当前用户登录问题
           // Cmn.Session.SetUserID("kdkkk"); //随便设置一个session 否则SessionID会变
        Cmn.Session.Set("cmn_ItfProxy_tmp","test");

        targetUrl = Cmn.Func.AddParamToUrl(targetUrl, "CurSessionID=" + Session.SessionID);

        Cmn.Log.WriteToFile("targetUrl", targetUrl);

        if (Request.Form.Count > 0) { //post方式
            string _postString = "";

            for (int _i = 0; _i < Request.Form.Count; _i++) {
                if (_postString != "") { _postString += "&"; }

                _postString += Request.Form.Keys[_i] + "=" + System.Web.HttpUtility.UrlEncode(Request.Form[_i].ToString(), Encoding.UTF8);
            }

            byte[] _postData = Encoding.GetEncoding("utf-8").GetBytes(_postString);
            _webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            byte[] _responseData = _webClient.UploadData(targetUrl, "POST", _postData);//得到返回字符流
            _retVal = Encoding.GetEncoding("utf-8").GetString(_responseData);//解码
        }
        else {
            Stream _stream = _webClient.OpenRead(targetUrl);

            StreamReader _rd = new StreamReader(_stream, Encoding.GetEncoding("utf-8"));
            _retVal = _rd.ReadToEnd();

            _stream.Close();

        }

        return _retVal;
    }
Пример #36
0
        public static void UploadData_InvalidArguments_ThrowExceptions()
        {
            var wc = new WebClient();

            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadData((string)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadData((string)null, null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadData((Uri)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadData((Uri)null, null, null); });

            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataAsync((Uri)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataAsync((Uri)null, null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataAsync((Uri)null, null, null, null); });

            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataTaskAsync((string)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataTaskAsync((string)null, null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataTaskAsync((Uri)null, null); });
            Assert.Throws<ArgumentNullException>("address", () => { wc.UploadDataTaskAsync((Uri)null, null, null); });

            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadData("http://localhost", null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadData("http://localhost", null, null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadData(new Uri("http://localhost"), null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadData(new Uri("http://localhost"), null, null); });

            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataAsync(new Uri("http://localhost"), null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataAsync(new Uri("http://localhost"), null, null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataAsync(new Uri("http://localhost"), null, null, null); });

            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataTaskAsync("http://localhost", null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataTaskAsync("http://localhost", null, null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataTaskAsync(new Uri("http://localhost"), null); });
            Assert.Throws<ArgumentNullException>("data", () => { wc.UploadDataTaskAsync(new Uri("http://localhost"), null, null); });
        }
Пример #37
0
 protected override Task<byte[]> UploadDataAsync(WebClient wc, string address, byte[] data) => Task.Run(() => wc.UploadData(address, data));
Пример #38
0
 public static async Task ConcurrentOperations_Throw()
 {
     await LoopbackServer.CreateServerAsync((server, url) =>
     {
         var wc = new WebClient();
         Task ignored = wc.DownloadDataTaskAsync(url); // won't complete
         Assert.Throws<NotSupportedException>(() => { wc.DownloadData(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadDataAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadDataTaskAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadString(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadStringAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadStringTaskAsync(url); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFile(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFileAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.DownloadFileTaskAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadData(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadDataAsync(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadDataTaskAsync(url, new byte[42]); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadString(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadStringAsync(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadStringTaskAsync(url, "42"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFile(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFileAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadFileTaskAsync(url, "path"); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValues(url, new NameValueCollection()); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValuesAsync(url, new NameValueCollection()); });
         Assert.Throws<NotSupportedException>(() => { wc.UploadValuesTaskAsync(url, new NameValueCollection()); });
         return Task.CompletedTask;
     });
 }
Пример #39
0
    IEnumerator createAndSendFileOnFtp(string id)
    {
        ExtraEvent.firePleaseWait(true);
        t = Time.time;
        debugString = "-started:"+t;
        yield return new WaitForSeconds(1);
        byte[] img = m_sendPic.EncodeToPNG();
        string fileName = Path.GetRandomFileName();
        fileName = fileName.Replace(".","");
        //		Debug.Log("Unique fName>" + fileName+"<");

        //		ALTERNATE VERSION VV DOESN'T WORK MOUAHAHAH ^^
        //		FileStream fs =  File.Open(Application.persistentDataPath+"/test.png",FileMode.Open);
        //		fs.Flush();
        //		fs.Write(img,0,img.Length);
        //		fs.Close();
        //
        //		string filename = "Bitcherland.png";
        //		FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://www.oneshot3d.com/ExtraTest/"+filename);
        //		ftpRequest.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName;
        //		ftpRequest.Credentials = new NetworkCredential("sys_pointcub","gx8FztlI7kpM");
        //
        ////		StreamReader sr = new StreamReader(Application.persistentDataPath+"/test.png");
        ////		byte[] fileContent = Encoding.UTF8.GetBytes(sr.ReadToEnd());
        ////		sr.Close();
        ////
        ////		ftpRequest.ContentLength = fileContent.Length;
        //
        //		Stream requestStream = ftpRequest.GetRequestStream();
        //		requestStream.Write(img,0,img.Length);
        //		requestStream.Close();
        //
        //		FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
        //
        ////      Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
        //    	Debug.Log("UploadFile complete, >"+response.StatusDescription);
        //        response.Close();

        debugString += "-startwc:"+Time.time;
        WebClient wc = new WebClient();

        wc.Credentials = new NetworkCredential("sys_pointcub","gx8FztlI7kpM"); //local

        wc.UploadData("ftp://www.pointcube.com/extrabat/img/"+fileName+".png",img);
        wc.Dispose();

        debugString += "-endwc:"+Time.time;
        Debug.Log("COROUTINE UPLOAD FINNISHED");
        yield return new WaitForSeconds(1);

        StartCoroutine(fileOnServer(id,fileName));
        yield return null;
    }
    /// <summary>
    /// Retrieve access or refresh token
    /// </summary>
    /// <param name="accessCode"></param>
    /// <param name="url"></param>
    /// <param name="urlData"></param>
    /// <param name="callbackUrl">Original callback URL (used for verification by some provider)</param>
    /// <returns></returns>
    private TokenResponse GetAccessToken(string accessCode, String url, String urlData, String callbackUrl)
    {
        urlData = urlData.Replace("{REDIRECT_URI}", HttpUtility.UrlEncode(callbackUrl));
        urlData = urlData.Replace("{TOKEN}", HttpUtility.UrlEncode(accessCode));
        urlData = urlData.Replace("{CLIENTID}", provider.ClientId);
        urlData = urlData.Replace("{CLIENTSECRET}", provider.Secret);
        // I don't think we need that one - if the provider requires refresh token, we'll be using the refresh URL instead
        //if (provider.RequiresRefreshToken.GetValueOrDefault())
        //    urlData += "&access_type=offline";
        try
        {
            var client = new WebClient();
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            // TODO: support for "GET" method
            byte[] response = client.UploadData(url, Encoding.ASCII.GetBytes(urlData));
            TokenResponse tResponse = JsonConvert.DeserializeObject<TokenResponse>(Encoding.ASCII.GetString(response));

            if (tResponse.error != null)
                throw new Exception(tResponse.error);
            return tResponse;
        }
        catch (Exception ex)
        {
            if (ex is WebException)
            {
                using (var sr = new StreamReader(((WebException)ex).Response.GetResponseStream()))
                {
                    String responseString = sr.ReadToEnd();
                    if (!String.IsNullOrEmpty(responseString))
                    {
                        _log.Warn("Error Response from OAuth provider: " + responseString);
                    }
                }
            }
            throw new ValidationException(String.Format("Unable to retrieve authorization token: {0}", ex.Message));
        }
    }
Пример #41
0
    public static string SendMessage(string Url, string strMessage)
    {
        string strResponse;
             // 初始化WebClient
             WebClient webClient = new WebClient();
             webClient.Headers.Add("Accept", "*/*");
             webClient.Headers.Add("Accept-Language", "zh-cn");
             webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

             try
             {
                 byte[] responseData = webClient.UploadData(Url, "POST", Encoding.GetEncoding("UTF-8").GetBytes(strMessage));
                 string srcString = Encoding.GetEncoding("UTF-8").GetString(responseData);
                 strResponse = srcString;
             }
             catch
             {
                 return "-1";
             }
             return strResponse;
    }
 private void GetAccessToken(string requestToken, string requestTokenSecret, string verifier, out string accessToken, out string accessTokenSecret, out string username)
 {
     Uri url = new Uri(provider.Host + provider.AccessTokenUrl);
     OAuthBase auth = new OAuthBase();
     String requestUrl, requestParams;
     String signature = auth.GenerateSignature(url, provider.ClientId, provider.Secret, requestToken, requestTokenSecret, provider.RequestTokenMethod ?? "POST",
         auth.GenerateTimeStamp(), auth.GenerateTimeStamp() + auth.GenerateNonce(), out requestUrl, out requestParams,
         new OAuthBase.QueryParameter("oauth_verifier", auth.UrlEncode(verifier)));
     WebClient webClient = new WebClient();
     byte[] response = webClient.UploadData(url, Encoding.ASCII.GetBytes(requestParams + "&oauth_signature=" + HttpUtility.UrlEncode(signature)));
     String[] tokenParts = Encoding.ASCII.GetString(response).Split('&');
     if (tokenParts.Length < 2)
     {
         throw new Exception("Unexpected response to access token request: " + Encoding.ASCII.GetString(response));
     }
     accessToken = null;
     accessTokenSecret = null;
     username = null;
     foreach (String tokenPart in tokenParts)
     {
         String[] pieces = tokenPart.Split('=');
         if (pieces.Length != 2)
         {
             throw new Exception("Unable to parse HTTP response: " + tokenPart); // should not happen
         }
         switch (pieces[0])
         {
             case OAuthBase.OAuthTokenKey:
                 accessToken = pieces[1];
                 break;
             case OAuthBase.OAuthTokenSecretKey:
                 accessTokenSecret = pieces[1];
                 break;
             case "screen_name": case "user_name":
                 // Twitter provides the user name back with this call, though it's not part of the standard.
                 // we'll capture it if it's provided and leave it null if not (it's not really required for anything anyway)
                 username = pieces[1];
                 break;
             default:
                 // ignore other values
                 break;
         }
     }
 }
Пример #43
0
 static void PushImage(string file)
 {
     Console.WriteLine (file);
     using (WebClient wc = new WebClient ()) {
         wc.Headers.Add ("X-Apple-AssetKey", "F92F9B91-954E-4D63-BB9A-EEC771ADE6E8");
         wc.Headers.Add ("User-Agent", "AirPlay/160.4 (Photos)");
         wc.Headers.Add ("X-Apple-Session-ID", "1bd6ceeb-fffd-456c-a09c-996053a7a08c");
         var data = File.ReadAllBytes (file);
         // FIXME: change address to match your device
         wc.UploadData ("http://your.apple.tv:7000/photo", "PUT", data);
     }
 }
Пример #44
0
    private JObject winkCallAPI(string url, string method = "", string sendcommand = "", bool requiresToken = true)
    {
        try
        {
            String responseString = string.Empty;
            JObject jsonResponse = new JObject();

            using (var xhr = new WebClient())
            {
                xhr.Headers[HttpRequestHeader.ContentType] = "application/json";

                if (requiresToken)
                    xhr.Headers.Add("Authorization", "Bearer " + myWink.WinkToken);

                byte[] result = null;

                if (String.IsNullOrWhiteSpace(sendcommand) && method.ToLower() != "post")
                {
                    result = xhr.DownloadData(url);
                }
                else
                {
                    byte[] data = Encoding.Default.GetBytes(sendcommand);
                    result = xhr.UploadData(url, method, data);
                }

                responseString = Encoding.Default.GetString(result);
            }

            if (responseString != null)
            {
                #if DEBUG
                if (url == "https://winkapi.quirky.com/users/me/wink_devices")
                {
                    if (myWink.winkUser.email.ToLower().Contains("trunzo"))
                    {
                        //Add Garage Door
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"garage_door_id\": \"8552\",\"name\": \"zTest Chamberlain\",\"locale\": \"en_us\",\"units\": {},\"created_at\": 1420250978,\"hidden_at\": null,\"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"af309d2e12b86bd1e5e63123db745dad703e46fb|garage_door-8552|user-123172\"}},\"user_ids\": [\"123172\"],\"triggers\": [],\"desired_state\": {\"position\": 1.0},\"manufacturer_device_model\": \"chamberlain_vgdo\",\"manufacturer_device_id\": \"1180839\",\"device_manufacturer\": \"chamberlain\",\"model_name\": \"MyQ Garage Door Controller\",\"upc_id\": \"26\",\"linked_service_id\": \"59900\",\"last_reading\": {\"connection\": true,\"connection_updated_at\": 1428535030.025161,\"position\": 1.0,\"position_updated_at\": 1428535020.76,\"position_opened\": \"N/A\",\"position_opened_updated_at\": 1428534916.709,\"battery\": 1.0,\"battery_updated_at\": 1428534350.3417819,\"fault\": false,\"fault_updated_at\": 1428534350.3417749,\"control_enabled\": true,\"control_enabled_updated_at\": 1428534350.3417563,\"desired_position\": 0.0,\"desired_position_updated_at\": 1428535030.0404377},\"lat_lng\": [33.162135,-97.090945],\"location\": \"\",\"order\": 0},");

                        //Add Honeywell Thermostat
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"thermostat_id\": \"27239\",\"name\": \"zTest Honeywell\",\"locale\": \"en_us\",\"units\": {\"temperature\": \"f\"},\"created_at\": 1419909349,\"hidden_at\": null,\"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"f5cb03e4101d1668ff7933a703a864b4984fce5a|thermostat-27239|user-123172\"}},\"user_ids\": [\"123172\",\"157050\"],\"triggers\": [],\"desired_state\": {\"mode\": \"heat_only\",\"powered\": true,\"min_set_point\": 20.0,\"max_set_point\": 22.777777777777779},\"manufacturer_device_model\": \"MANHATTAN\",\"manufacturer_device_id\": \"798165\",\"device_manufacturer\": \"honeywell\",\"model_name\": \"Honeywell Wi-Fi Smart Thermostat\",\"upc_id\": \"151\",\"hub_id\": null,\"local_id\": \"00D02D49A90A\",\"radio_type\": null,\"linked_service_id\": \"57563\",\"last_reading\": {\"connection\": true,\"connection_updated_at\": 1428536316.8312173,\"mode\": \"heat_only\",\"mode_updated_at\": 1428536316.8312581,\"powered\": true,\"powered_updated_at\": 1428536316.831265,\"min_set_point\": 20.0,\"min_set_point_updated_at\": 1428536316.8312485,\"max_set_point\": 22.777777777777779,\"max_set_point_updated_at\": 1428536316.8312287,\"temperature\": 22.777777777777779,\"temperature_updated_at\": 1428536316.8312783,\"external_temperature\": null,\"external_temperature_updated_at\": null,\"deadband\": 1.6666666666666667,\"deadband_updated_at\": 1428536316.831311,\"min_min_set_point\": 4.4444444444444446,\"min_min_set_point_updated_at\": 1428536316.8313046,\"max_min_set_point\": 29.444444444444443,\"max_min_set_point_updated_at\": 1428536316.8312914,\"min_max_set_point\": 16.666666666666668,\"min_max_set_point_updated_at\": 1428536316.8312984,\"max_max_set_point\": 37.222222222222221,\"max_max_set_point_updated_at\": 1428536316.831285,\"modes_allowed\": [\"auto\",\"cool_only\",\"heat_only\"],\"modes_allowed_updated_at\": 1428536316.8313177,\"units\": \"f\",\"units_updated_at\": 1428536316.8312719,\"desired_mode\": \"heat_only\",\"desired_mode_updated_at\": 1428365474.3775809,\"desired_powered\": true,\"desired_powered_updated_at\": 1424823532.9645114,\"desired_min_set_point\": 20.0,\"desired_min_set_point_updated_at\": 1428509375.1094887,\"desired_max_set_point\": 22.777777777777779,\"desired_max_set_point_updated_at\": 1428509375.109503},\"lat_lng\": [33.162074,-97.090928],\"location\": \"\",\"smart_schedule_enabled\": false},");

                        //Add Nest Thermostat
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"thermostat_id\": \"49534\",\"name\": \"zTest Nest\",\"locale\": \"en_us\",\"units\": {\"temperature\": \"f\"},\"created_at\": 1427241058,\"hidden_at\": null,\"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"0e67d43624e47b3633273f1236b7cde2c1823ac7|thermostat-49410|user-81926\"}},\"user_ids\": [\"81926\"],\"triggers\": [],\"desired_state\": {\"mode\": \"cool_only\",\"powered\": true,\"min_set_point\": 21.0,\"max_set_point\": 22.0,\"users_away\": false,\"fan_timer_active\": false},\"manufacturer_device_model\": \"nest\",\"manufacturer_device_id\": \"pHNukJTND3MHRBT9zks77kxx11Qobba_\",\"device_manufacturer\": \"nest\",\"model_name\": \"Learning Thermostat\",\"upc_id\": \"168\",\"hub_id\": null,\"local_id\": null,\"radio_type\": null,\"linked_service_id\": \"92972\",\"last_reading\": {\"connection\": true,\"connection_updated_at\": 1428516397.2914052,\"mode\": \"cool_only\",\"mode_updated_at\": 1428516397.2914376,\"powered\": true,\"powered_updated_at\": 1428516397.2914565,\"min_set_point\": 21.0,\"min_set_point_updated_at\": 1428461324.5980272,\"max_set_point\": 22.0,\"max_set_point_updated_at\": 1428516397.2914746,\"users_away\": false,\"users_away_updated_at\": 1428516397.2914917,\"fan_timer_active\": false,\"fan_timer_active_updated_at\": 1428516397.2914684,\"temperature\": 22.0,\"temperature_updated_at\": 1428516397.2914257,\"external_temperature\": null,\"external_temperature_updated_at\": null,\"deadband\": 1.5,\"deadband_updated_at\": 1428516397.2914317,\"min_min_set_point\": null,\"min_min_set_point_updated_at\": null,\"max_min_set_point\": null,\"max_min_set_point_updated_at\": null,\"min_max_set_point\": null,\"min_max_set_point_updated_at\": null,\"max_max_set_point\": null,\"max_max_set_point_updated_at\": null,\"modes_allowed\": [\"auto\",\"heat_only\",\"cool_only\"],\"modes_allowed_updated_at\": 1428516397.2914805,\"units\": \"f\",\"units_updated_at\": 1428516397.2914197,\"eco_target\": false,\"eco_target_updated_at\": 1428516397.2914433,\"manufacturer_structure_id\": \"kdCrRKp3UahHp8xWEoJBRYX9xnQWDsoU1sb5ej9Mp5Zb41WEIOKJtg\",\"manufacturer_structure_id_updated_at\": 1428516397.2914503,\"has_fan\": true,\"has_fan_updated_at\": 1428516397.2914622,\"fan_duration\": 0,\"fan_duration_updated_at\": 1428516397.2914863,\"last_error\": null,\"last_error_updated_at\": 1427241058.6980464,\"desired_mode\": \"cool_only\",\"desired_mode_updated_at\": 1427593066.90498,\"desired_powered\": true,\"desired_powered_updated_at\": 1428462838.6427567,\"desired_min_set_point\": 21.0,\"desired_min_set_point_updated_at\": 1428427791.3297703,\"desired_max_set_point\": 22.0,\"desired_max_set_point_updated_at\": 1428497187.9092989,\"desired_users_away\": false,\"desired_users_away_updated_at\": 1428440888.9921448,\"desired_fan_timer_active\": false,\"desired_fan_timer_active_updated_at\": 1427241058.6981435},\"lat_lng\": [null,null],\"location\": \"\",\"smart_schedule_enabled\": false},");

                        //Add Refuel
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"propane_tank_id\": \"6521\",\"name\": \"zTest Refuel\",\"locale\": \"en_us\",\"units\": {\"temperature\": \"f\"},\"created_at\": 1419569612,\"hidden_at\": null,\"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"5055752531a8aac104827ec4ba2a3366038ee15a|propane_tank-6521|user-123172\"}},\"user_ids\": [\"123172\",\"157050\"],\"triggers\": [],\"device_manufacturer\": \"quirky_ge\",\"model_name\": \"Refuel\",\"upc_id\": \"17\",\"last_reading\": {\"connection\": true,\"battery\": 0.52,\"remaining\": 0.5},\"lat_lng\": [33.162101,-97.090547],\"location\": \"76210\",\"mac_address\": \"0c2a6907025a\",\"serial\": \"ACAB00033589\",\"tare\": 18.0,\"tank_changed_at\": 1421352479},");

                        //Add Nest Protect
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"smoke_detector_id\": \"10076\", \"name\": \"zTest Nest Protect\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1419086573, \"hidden_at\": null, \"capabilities\": {}, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"5882005d3a98dbbd335c2cf778a6734557cd1f2f|smoke_detector-10076|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"manufacturer_device_model\": \"nest\", \"manufacturer_device_id\": \"VpXN4GQ7MUD5QqV8vgvQOExx11Qobba_\", \"device_manufacturer\": \"nest\", \"model_name\": \"Smoke + Carbon Monoxide Detector\", \"upc_id\": \"170\", \"hub_id\": null, \"local_id\": null, \"radio_type\": null, \"linked_service_id\": \"50847\", \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428865904.1217248, \"battery\": 1.0, \"battery_updated_at\": 1428865904.1217616, \"co_detected\": false, \"co_detected_updated_at\": 1428865904.1217353, \"smoke_detected\": false, \"smoke_detected_updated_at\": 1428865904.1217477, \"test_activated\": null, \"test_activated_updated_at\": 1428855697.3881633, \"smoke_severity\": 0.0, \"smoke_severity_updated_at\": 1428865904.1217549, \"co_severity\": 0.0, \"co_severity_updated_at\": 1428865904.1217415 }, \"lat_lng\": [ null, null ], \"location\": \"\" },");

                        //Add Relay & Related
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"hub_id\": \"132595\", \"name\": \"zTest Wink Relay\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1428545678, \"hidden_at\": null, \"capabilities\": { \"oauth2_clients\": [ \"wink_project_one\" ] }, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"d9be1fe3abeb9fc46bec54a7cb62719a5a576c86|hub-132595|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"triggers\": [], \"desired_state\": { \"pairing_mode\": null }, \"manufacturer_device_model\": \"wink_project_one\", \"manufacturer_device_id\": null, \"device_manufacturer\": \"wink\", \"model_name\": \"Wink Relay\", \"upc_id\": \"186\", \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428865074.9676549, \"agent_session_id\": \"9c99e3314c3a39f2eb9830a78d10684c\", \"agent_session_id_updated_at\": 1428855693.8299525, \"remote_pairable\": null, \"remote_pairable_updated_at\": null, \"updating_firmware\": false, \"updating_firmware_updated_at\": 1428855688.0774271, \"app_rootfs_version\": \"1.0.221\", \"app_rootfs_version_updated_at\": 1428855697.3881633, \"firmware_version\": \"1.0.221\", \"firmware_version_updated_at\": 1428855697.3881423, \"update_needed\": false, \"update_needed_updated_at\": 1428855697.3881698, \"mac_address\": \"B4:79:A7:0F:F7:DF\", \"mac_address_updated_at\": 1428855697.3881495, \"ip_address\": \"192.168.1.187\", \"ip_address_updated_at\": 1428855697.3881567, \"hub_version\": \"user\", \"hub_version_updated_at\": 1428855697.3881316, \"pairing_mode\": null, \"pairing_mode_updated_at\": 1428545678.0519505, \"desired_pairing_mode\": null, \"desired_pairing_mode_updated_at\": 1428545678.0519564 }, \"lat_lng\": [ null, null ], \"location\": \"\", \"configuration\": null, \"update_needed\": true, \"uuid\": \"9bb6a0d5-30f2-4bf7-8b37-d667c30e05bc\" },");
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"binary_switch_id\": \"46401\", \"name\": \"zTest Relay Switch A\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1428545701, \"hidden_at\": null, \"capabilities\": { \"configuration\": null }, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"bb1cb7a5d146cbc2cf09dca3655f684b2e24be89|binary_switch-46401|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"triggers\": [], \"desired_state\": { \"powered\": false, \"powering_mode\": \"dumb\" }, \"manufacturer_device_model\": null, \"manufacturer_device_id\": null, \"device_manufacturer\": null, \"model_name\": null, \"upc_id\": null, \"gang_id\": \"6776\", \"hub_id\": \"132595\", \"local_id\": \"1\", \"radio_type\": \"project_one\", \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428855698.9869163, \"powered\": false, \"powered_updated_at\": 1428855698.9869256, \"powering_mode\": \"dumb\", \"powering_mode_updated_at\": 1428545815.5253267, \"consumption\": null, \"consumption_updated_at\": null, \"cost\": null, \"cost_updated_at\": null, \"budget_percentage\": null, \"budget_percentage_updated_at\": null, \"budget_velocity\": null, \"budget_velocity_updated_at\": null, \"summation_delivered\": null, \"summation_delivered_updated_at\": null, \"sum_delivered_multiplier\": null, \"sum_delivered_multiplier_updated_at\": null, \"sum_delivered_divisor\": null, \"sum_delivered_divisor_updated_at\": null, \"sum_delivered_formatting\": null, \"sum_delivered_formatting_updated_at\": null, \"sum_unit_of_measure\": null, \"sum_unit_of_measure_updated_at\": null, \"desired_powered\": false, \"desired_powered_updated_at\": 1428546752.8178129, \"desired_powering_mode\": \"dumb\", \"desired_powering_mode_updated_at\": 1428545815.5253191 }, \"current_budget\": null, \"lat_lng\": [ 0.0, 0.0 ], \"location\": \"\", \"order\": 0 },");
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"binary_switch_id\": \"30320\", \"name\": \"zTest Relay Switch B\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1422813943, \"hidden_at\": null, \"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"8afe2bdfa540e4459b510bff44db636388afea88|binary_switch-30320|user-186645\"}},\"user_ids\": [\"186645\"],\"triggers\": [],\"desired_state\": {\"powered\": false,\"powering_mode\": \"none\"},\"manufacturer_device_model\": null,\"manufacturer_device_id\": null,\"device_manufacturer\": null,\"model_name\": null,\"upc_id\": null,\"gang_id\": \"2997\",\"hub_id\": \"98045\",\"local_id\": \"2\",\"radio_type\": \"project_one\",\"last_reading\": {\"connection\": true,\"connection_updated_at\": 1429016828.833034,\"powered\": false,\"powered_updated_at\": 1429016828.8330438,\"powering_mode\": \"none\",\"powering_mode_updated_at\": 1422824216.9928842,\"consumption\": null,\"consumption_updated_at\": null,\"cost\": null,\"cost_updated_at\": null,\"budget_percentage\": null,\"budget_percentage_updated_at\": null,\"budget_velocity\": null,\"budget_velocity_updated_at\": null,\"summation_delivered\": null,\"summation_delivered_updated_at\": null,\"sum_delivered_multiplier\": null,\"sum_delivered_multiplier_updated_at\": null,\"sum_delivered_divisor\": null,\"sum_delivered_divisor_updated_at\": null,\"sum_delivered_formatting\": null,\"sum_delivered_formatting_updated_at\": null,\"sum_unit_of_measure\": null,\"sum_unit_of_measure_updated_at\": null,\"desired_powered\": false,\"desired_powered_updated_at\": 1422824138.418901,\"desired_powering_mode\": \"none\",\"desired_powering_mode_updated_at\": 1422824216.9928727},\"current_budget\": null,\"lat_lng\": [0.0,0.0],\"location\": \"\",\"order\": 0},");
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"button_id\": \"13333\", \"name\": \"zTest Smart Button 1\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1428545701, \"hidden_at\": null, \"capabilities\": {}, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"2894740376a764e392d566474aac56f634c3731f|button-13333|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"manufacturer_device_model\": null, \"manufacturer_device_id\": null, \"device_manufacturer\": null, \"model_name\": null, \"upc_id\": null, \"gang_id\": \"6776\", \"hub_id\": \"132595\", \"local_id\": \"4\", \"radio_type\": \"project_one\", \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428855697.7729235, \"pressed\": false, \"pressed_updated_at\": 1428855697.7729335, \"long_pressed\": null, \"long_pressed_updated_at\": null }, \"lat_lng\": [ null, null ], \"location\": \"\" },");
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"button_id\": \"13334\", \"name\": \"zTest Smart Button 2\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1428545701, \"hidden_at\": null, \"capabilities\": {}, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"51c9e90c1b352231a0ce9bdbfa1295c052af91f2|button-13334|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"manufacturer_device_model\": null, \"manufacturer_device_id\": null, \"device_manufacturer\": null, \"model_name\": null, \"upc_id\": null, \"gang_id\": \"6776\", \"hub_id\": \"132595\", \"local_id\": \"5\", \"radio_type\": \"project_one\", \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428855697.9626672, \"pressed\": false, \"pressed_updated_at\": 1428855697.962677, \"long_pressed\": null, \"long_pressed_updated_at\": null }, \"lat_lng\": [ null, null ], \"location\": \"\" },");
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"gang_id\": \"6776\", \"name\": \"zTest Gang\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1428545678, \"hidden_at\": null, \"capabilities\": {}, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"1d8877fe2c53439330ef7e72548c6fa38e111420|gang-6776|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"desired_state\": {}, \"manufacturer_device_model\": \"wink_project_one\", \"manufacturer_device_id\": null, \"device_manufacturer\": null, \"model_name\": null, \"upc_id\": null, \"hub_id\": \"132595\", \"local_id\": null, \"radio_type\": null, \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1428545678.122422 }, \"lat_lng\": [ null, null ], \"location\": \"\" },");

                        //Spotter
                                responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"last_event\":{\"brightness_occurred_at\":1428961404.2836313,\"loudness_occurred_at\":1427547964.9292188,\"vibration_occurred_at\":1428879300.9600453},\"sensor_threshold_events\":[],\"sensor_pod_id\":\"40794\",\"name\":\"zTest Spotter\",\"locale\":\"en_us\",\"units\":{\"temperature\":\"f\"},\"created_at\":1422657639,\"hidden_at\":null,\"capabilities\":{\"sensor_types\":[{\"type\":\"percentage\",\"field\":\"battery\"},{\"type\":\"percentage\",\"field\":\"brightness\"},{\"type\":\"boolean\",\"field\":\"external_power\"},{\"type\":\"integer_percentage\",\"field\":\"humidity\"},{\"type\":\"percentage\",\"field\":\"loudness\"},{\"type\":\"float\",\"field\":\"temperature\"},{\"type\":\"boolean\",\"field\":\"vibration\"}]},\"subscription\":{\"pubnub\":{\"subscribe_key\":\"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\":\"959bda140ade2f77ded3fd968bfac2242489175e|sensor_pod-40794|user-186645\"}},\"user_ids\":[\"186645\"],\"triggers\":[],\"desired_state\":{},\"manufacturer_device_model\":\"quirky_ge_spotter\",\"manufacturer_device_id\":null,\"device_manufacturer\":\"quirky_ge\",\"model_name\":\"Spotter\",\"upc_id\":\"25\",\"gang_id\":null,\"hub_id\":null,\"local_id\":null,\"radio_type\":null,\"last_reading\":{\"connection\":true,\"connection_updated_at\":1428969581.0099306,\"agent_session_id\":null,\"agent_session_id_updated_at\":1425384214.8524168,\"battery\":0.98,\"battery_updated_at\":1428969581.0099251,\"brightness\":1.0,\"brightness_updated_at\":1428969581.0098875,\"external_power\":true,\"external_power_updated_at\":1428969581.0098965,\"humidity\":35,\"humidity_updated_at\":1428969581.0099025,\"loudness\":0.0,\"loudness_updated_at\":1428969581.0099192,\"temperature\":19.0,\"temperature_updated_at\":1428969581.0099139,\"vibration\":false,\"vibration_updated_at\":1428969581.0099082,\"brightness_true\":\"N/A\",\"brightness_true_updated_at\":1428961404.2836313,\"loudness_true\":\"N/A\",\"loudness_true_updated_at\":1427547964.9292188,\"vibration_true\":\"N/A\",\"vibration_true_updated_at\":1428879300.9600453},\"lat_lng\":[0.0,0.0],\"location\":\"\",\"mac_address\":\"0c2a690656b3\",\"serial\":\"ABAB00029469\",\"uuid\":\"005f5493-2ab6-46fa-ab7d-f2932c37dd4a\"},");

                        //Rachio Iro
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{\"sprinkler_id\": \"1483\",\"name\": \"Sprinkler\",\"locale\": \"en_us\",\"units\": {},\"created_at\": 1429295028,\"hidden_at\": null,\"capabilities\": {},\"subscription\": {\"pubnub\": {\"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\",\"channel\": \"ecbd8151da8524635b2dfd777c4f55f33a042285|sprinkler-1483|user-186645\"}},\"user_ids\": [\"186645\"],\"desired_state\": {\"master_valve\": false,\"rain_sensor\": false,\"schedule_enabled\": false,\"run_zone_indices\": [],\"run_zone_durations\": []},\"manufacturer_device_model\": \"rachio_iro\",\"manufacturer_device_id\": \"b26d4e70-f4df-481a-9149-c9bac4c3a09e\",\"device_manufacturer\": \"rachio\",\"model_name\": \"Iro\",\"upc_id\": \"152\",\"linked_service_id\": \"100792\",\"last_reading\": {\"connection\": true,\"connection_updated_at\": 1429477160.725,\"master_valve\": false,\"master_valve_updated_at\": 1429477160.725,\"rain_sensor\": false,\"rain_sensor_updated_at\": 1429477160.725,\"schedule_enabled\": false,\"schedule_enabled_updated_at\": 1429477160.725,\"run_zone_indices\": [],\"run_zone_indices_updated_at\": 1429361044.5683227,\"run_zone_durations\": [],\"run_zone_durations_updated_at\": 1429361044.5683227,\"desired_master_valve\": false,\"desired_master_valve_updated_at\": 1429361044.6298194,\"desired_rain_sensor\": false,\"desired_rain_sensor_updated_at\": 1429361042.534966,\"desired_schedule_enabled\": false,\"desired_schedule_enabled_updated_at\": 1429361044.6298397,\"desired_run_zone_indices\": [],\"desired_run_zone_indices_updated_at\": 1429361042.5349822,\"desired_run_zone_durations\": [],\"desired_run_zone_durations_updated_at\": 1429361042.5349896},\"lat_lng\": [41.38983,-81.42602],\"location\": \"\",\"zones\": [{\"name\": \"Top Driveway\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6298468,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6298535,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6298602,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6298668,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.629873,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6298814},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 0,\"zone_id\": \"12501\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Driveway Bottom\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6298881,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6298945,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6299007,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6299071,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6299136,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6299202},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 1,\"zone_id\": \"12502\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Tree Lawn\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6299269,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6299338,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6299408,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6299474,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6299543,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.629961},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 2,\"zone_id\": \"12503\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Back Right\",\"desired_state\": {\"enabled\": false,\"enabled_updated_at\": 1429361044.6299675,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6299734,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6299799,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6299863,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6299949,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6300077},\"last_reading\": {\"enabled\": false,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 3,\"zone_id\": \"12504\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Mailbox\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6300216,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6300349,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6300464,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.630054,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6300609,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6300678},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 4,\"zone_id\": \"12505\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Back Center\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6300743,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6300812,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6300881,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6300948,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6301012,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6301079},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 5,\"zone_id\": \"12506\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Back Left\",\"desired_state\": {\"enabled\": true,\"enabled_updated_at\": 1429361044.6301141,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6301203,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6301262,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6301327,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6301389,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6301456},\"last_reading\": {\"enabled\": true,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 6,\"zone_id\": \"12507\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"},{\"name\": \"Zone 8\",\"desired_state\": {\"enabled\": false,\"enabled_updated_at\": 1429361044.630152,\"shade\": \"none\",\"shade_updated_at\": 1429361044.6301584,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429361044.6301646,\"soil\": \"top_soil\",\"soil_updated_at\": 1429361044.6301739,\"slope\": \"flat\",\"slope_updated_at\": 1429361044.6301811,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429361044.6301878},\"last_reading\": {\"enabled\": false,\"enabled_updated_at\": 1429477160.725,\"shade\": \"none\",\"shade_updated_at\": 1429477160.725,\"nozzle\": \"fixed_spray_head\",\"nozzle_updated_at\": 1429477160.725,\"soil\": \"top_soil\",\"soil_updated_at\": 1429477160.725,\"slope\": \"flat\",\"slope_updated_at\": 1429477160.725,\"vegetation\": \"grass\",\"vegetation_updated_at\": 1429477160.725,\"powered\": false,\"powered_updated_at\": 1429361044.5683227},\"zone_index\": 7,\"zone_id\": \"12508\",\"parent_object_type\": \"sprinkler\",\"parent_object_id\": \"1483\"}]},");

                        //Ascend
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"garage_door_id\": \"16896\", \"name\": \"zTest Ascend Garage Door\", \"locale\": \"en_us\", \"units\": {}, \"created_at\": 1430344326, \"hidden_at\": null, \"capabilities\": {}, \"subscription\": { \"pubnub\": { \"subscribe_key\": \"sub-c-f7bf7f7e-0542-11e3-a5e8-02ee2ddab7fe\", \"channel\": \"9fe350e72a807190df334cd839a00992f59446b2|garage_door-16896|user-145398\" } }, \"user_ids\": [ \"145398\" ], \"triggers\": [], \"desired_state\": { \"position\": 0.0, \"laser\": false, \"calibration_enabled\": false }, \"manufacturer_device_model\": \"quirky_ge_ascend\", \"manufacturer_device_id\": null, \"device_manufacturer\": \"quirky_ge\", \"model_name\": \"Ascend\", \"upc_id\": \"182\", \"linked_service_id\": null, \"last_reading\": { \"connection\": true, \"connection_updated_at\": 1430362778.3658881, \"position\": 0.0, \"position_updated_at\": 1430362778.3658676, \"position_opened\": \"N/A\", \"position_opened_updated_at\": 1430351386.88027, \"battery\": null, \"battery_updated_at\": null, \"fault\": false, \"fault_updated_at\": 1430362778.3658946, \"control_enabled\": null, \"control_enabled_updated_at\": null, \"laser\": false, \"laser_updated_at\": 1430362778.3658564, \"buzzer\": null, \"buzzer_updated_at\": null, \"led\": null, \"led_updated_at\": null, \"moving\": null, \"moving_updated_at\": null, \"calibrated\": true, \"calibrated_updated_at\": 1430362778.3658812, \"calibration_enabled\": false, \"calibration_enabled_updated_at\": 1430362778.3658745, \"last_error\": null, \"last_error_updated_at\": 1430362778.3659008, \"desired_position\": 0.0, \"desired_position_updated_at\": 1430362531.397609, \"desired_laser\": false, \"desired_laser_updated_at\": 1430345748.1740961, \"desired_calibration_enabled\": false, \"desired_calibration_enabled_updated_at\": 1430345759.9318135 }, \"lat_lng\": [ 41.675863, -81.287492 ], \"location\": \"44060\", \"mac_address\": null, \"serial\": \"20000c2a69088729\", \"order\": null},");

                        //T
                        //        responseString = responseString.Replace("{\"data\":[", "{\"data\":[" + "{ \"last_event\" : { \"brightness_occurred_at\" : null, \"loudness_occurred_at\" : null, \"vibration_occurred_at\" : null }, \"sensor_pod_id\" : \"53479\", \"name\" : \"Bedroom Sensor\", \"locale\" : \"en_us\", \"units\" : {}, \"created_at\" : 1427985576, \"hidden_at\" : null, \"capabilities\" : { \"sensor_types\" : [{ \"field\" : \"motion\", \"type\" : \"boolean\" } ] }, \"triggers\" : [], \"desired_state\" : {}, \"manufacturer_device_model\" : \"ecolink_pir_zwavve2\", \"manufacturer_device_id\" : null, \"device_manufacturer\" : \"Ecolink\", \"model_name\" : \"Motion Sensor\", \"upc_id\" : \"173\", \"gang_id\" : null, \"hub_id\" : \"45262\", \"local_id\" : \"19\", \"radio_type\" : \"zwave\", \"last_reading\" : { \"connection\" : true, \"connection_updated_at\" : 1431625783.7867568, \"agent_session_id\" : \"FALSE\", \"agent_session_id_updated_at\" : 1431625783.7867672, \"motion\" : true, \"motion_updated_at\" : 1431625783.7867749, \"motion_true\" : \"N/A\", \"motion_true_updated_at\" : 1431625783.7867839, \"agent_session_id_changed_at\" : 1431625783.7867672, \"motion_changed_at\" : 1431625783.7867749 }, \"lat_lng\" : [ 39.024424, -77.038657 ], \"location\" : \"\", \"uuid\" : \"e9eaeaf1-2ce4-46d4-adb6-6f3f560a0594\" }, { \"last_event\" : { \"brightness_occurred_at\" : null, \"loudness_occurred_at\" : null, \"vibration_occurred_at\" : null }, \"sensor_pod_id\" : \"53481\", \"name\" : \"Bar sensor\", \"locale\" : \"en_us\", \"units\" : {}, \"created_at\" : 1427985745, \"hidden_at\" : null, \"capabilities\" : { \"sensor_types\" : [{ \"field\" : \"motion\", \"type\" : \"boolean\" } ] }, \"triggers\" : [], \"desired_state\" : {}, \"manufacturer_device_model\" : \"ecolink_pir_zwavve2\", \"manufacturer_device_id\" : null, \"device_manufacturer\" : \"Ecolink\", \"model_name\" : \"Motion Sensor\", \"upc_id\" : \"173\", \"gang_id\" : null, \"hub_id\" : \"45262\", \"local_id\" : \"21\", \"radio_type\" : \"zwave\", \"last_reading\" : { \"connection\" : true, \"connection_updated_at\" : 1431626950.371877, \"agent_session_id\" : \"FALSE\", \"agent_session_id_updated_at\" : 1431626950.3718965, \"motion\" : false, \"motion_updated_at\" : 1431626950.3719103, \"motion_true\" : \"N/A\", \"motion_true_updated_at\" : 1431626950.3719225, \"agent_session_id_changed_at\" : 1431626950.3718965, \"motion_changed_at\" : 1431626950.3719103 }, \"lat_lng\" : [ 39.024424, -77.038657 ], \"location\" : \"\", \"uuid\" : \"6e4fb2d0-0c36-4a20-8da4-dd2250e55d6a\" }, { \"last_event\" : { \"brightness_occurred_at\" : null, \"loudness_occurred_at\" : null, \"vibration_occurred_at\" : null }, \"sensor_pod_id\" : \"60402\", \"name\" : \"Basement Door\", \"locale\" : \"en_us\", \"units\" : {}, \"created_at\" : 1430514447, \"hidden_at\" : null, \"capabilities\" : { \"sensor_types\" : [{ \"field\" : \"opened\", \"type\" : \"boolean\" }, { \"field\" : \"battery\", \"type\" : \"percentage\" }, { \"field\" : \"tamper_detected\", \"type\" : \"boolean\" } ], \"polling_interval\" : 4200, \"home_security_device\" : true, \"offline_notification\" : true }, \"triggers\" : [], \"desired_state\" : {}, \"manufacturer_device_model\" : \"quirky_ge_tripper\", \"manufacturer_device_id\" : null, \"device_manufacturer\" : \"quirky_ge\", \"model_name\" : \"Tripper\", \"upc_id\" : \"184\", \"gang_id\" : null, \"hub_id\" : \"45262\", \"local_id\" : \"34\", \"radio_type\" : \"zigbee\", \"last_reading\" : { \"connection\" : true, \"connection_updated_at\" : 1431626601.5417626, \"agent_session_id\" : null, \"agent_session_id_updated_at\" : 1430514451.8775995, \"firmware_version\" : \"1.8b00 / 5.1b21\", \"firmware_version_updated_at\" : 1431626601.5417826, \"firmware_date_code\" : \"20150120\", \"firmware_date_code_updated_at\" : 1431626601.5417743, \"opened\" : false, \"opened_updated_at\" : 1431626601.541836, \"battery\" : 1.0, \"battery_updated_at\" : 1431626601.5418434, \"tamper_detected\" : false, \"tamper_detected_updated_at\" : 1431626601.5418506, \"tamper_detected_true\" : null, \"tamper_detected_true_updated_at\" : null, \"battery_voltage\" : 29, \"battery_voltage_updated_at\" : 1431626601.54179, \"battery_alarm_mask\" : 15, \"battery_alarm_mask_updated_at\" : 1431626601.5417976, \"battery_voltage_min_threshold\" : 24, \"battery_voltage_min_threshold_updated_at\" : 1431626601.5418057, \"battery_voltage_threshold_1\" : 24, \"battery_voltage_threshold_1_updated_at\" : 1431626601.5418136, \"battery_voltage_threshold_2\" : 24, \"battery_voltage_threshold_2_updated_at\" : 1431626601.5418212, \"battery_voltage_threshold_3\" : 25, \"battery_voltage_threshold_3_updated_at\" : 1431626601.5418289, \"opened_changed_at\" : 1431626601.541836, \"battery_voltage_changed_at\" : 1431549393.1340518 }, \"lat_lng\" : [ 39.024242, -77.038966 ], \"location\" : \"\", \"uuid\" : \"52d5f095-6fc1-4256-8f4e-ce3c1d8b9215\" }, { \"last_event\" : { \"brightness_occurred_at\" : null, \"loudness_occurred_at\" : null, \"vibration_occurred_at\" : null }, \"sensor_pod_id\" : \"60965\", \"name\" : \"Front door\", \"locale\" : \"en_us\", \"units\" : {}, \"created_at\" : 1430666191, \"hidden_at\" : null, \"capabilities\" : { \"sensor_types\" : [{ \"field\" : \"opened\", \"type\" : \"boolean\" }, { \"field\" : \"battery\", \"type\" : \"percentage\" }, { \"field\" : \"tamper_detected\", \"type\" : \"boolean\" } ], \"polling_interval\" : 4200, \"home_security_device\" : true, \"offline_notification\" : true }, \"triggers\" : [], \"desired_state\" : {}, \"manufacturer_device_model\" : \"quirky_ge_tripper\", \"manufacturer_device_id\" : null, \"device_manufacturer\" : \"quirky_ge\", \"model_name\" : \"Tripper\", \"upc_id\" : \"184\", \"gang_id\" : null, \"hub_id\" : \"45262\", \"local_id\" : \"35\", \"radio_type\" : \"zigbee\", \"last_reading\" : { \"connection\" : true, \"connection_updated_at\" : 1431619864.8199573, \"agent_session_id\" : null, \"agent_session_id_updated_at\" : 1430666193.5535953, \"firmware_version\" : \"1.8b00 / 5.1b21\", \"firmware_version_updated_at\" : 1431619864.8199759, \"firmware_date_code\" : \"20150120\", \"firmware_date_code_updated_at\" : 1431619864.8199678, \"opened\" : true, \"opened_updated_at\" : 1431619864.8200295, \"battery\" : 1.0, \"battery_updated_at\" : 1431619864.8200362, \"tamper_detected\" : false, \"tamper_detected_updated_at\" : 1431619864.8200431, \"tamper_detected_true\" : \"N/A\", \"tamper_detected_true_updated_at\" : 1430666193.5537961, \"battery_voltage\" : 28, \"battery_voltage_updated_at\" : 1431619864.819983, \"battery_alarm_mask\" : 15, \"battery_alarm_mask_updated_at\" : 1431619864.8199911, \"battery_voltage_min_threshold\" : 24, \"battery_voltage_min_threshold_updated_at\" : 1431619864.819999, \"battery_voltage_threshold_1\" : 24, \"battery_voltage_threshold_1_updated_at\" : 1431619864.8200069, \"battery_voltage_threshold_2\" : 24, \"battery_voltage_threshold_2_updated_at\" : 1431619864.820015, \"battery_voltage_threshold_3\" : 25, \"battery_voltage_threshold_3_updated_at\" : 1431619864.8200226, \"opened_changed_at\" : 1431569313.1120057, \"battery_voltage_changed_at\" : 1431535108.6598671 }, \"lat_lng\" : [ 39.024228, -77.038927 ], \"location\" : \"\", \"uuid\" : \"d396485b-4125-4e0b-8891-c847618b0d0c\" },");
                    }
                }
                #endif
                jsonResponse = JObject.Parse(responseString);
                if (jsonResponse != null)
                {
                    return jsonResponse;
                }
            }
        }
        catch (Exception ex)
        {
            string em = ex.Message;
            if (em.Contains("404"))
                return JObject.Parse("{\"error\":404}");
        }
        return null;
    }