예제 #1
0
        public LaunchData Launch(string launchUrl, string launchToken)
        {
            this.launchToken = launchToken;
            this.launchUrl   = launchUrl;
            client           = new HttpClient();
            HttpResponseMessage responseMessage = null;
            var _launchData = new LaunchData();

            try
            {
                responseMessage = client.PostAsync(launchUrl + "launch/" + launchToken, null).Result;
            }
            catch (Exception e)
            {
                _launchData.response = e.Message;
            }
            if (responseMessage != null)
            {
                string responseText = responseMessage.Content.ReadAsStringAsync().Result;
                var    status       = responseMessage.StatusCode;
                string cookies      = responseMessage.Headers.GetValues("set-cookie").ElementAt(0);
                var    cookieParser = new System.Net.CookieContainer();
                cookieParser.SetCookies(new Uri(launchUrl), cookies);
                CookieCollection parsedCookies = cookieParser.GetCookies(new Uri(launchUrl));
                this.cookie = parsedCookies["connect.sid"];
                try
                {
                    LaunchData jsonResponse = JsonConvert.DeserializeObject <LaunchData>(responseText);
                    _launchData = jsonResponse;
                }
                catch (Exception e)
                {
                    _launchData.response = responseText;
                }
                this.launchData = _launchData;
                return(_launchData);
            }
            else
            {
                this.launchData = _launchData;
                return(_launchData);
            }
        }
예제 #2
0
 public LaunchData Launch(string launchUrl, string launchToken)
 {
     this.launchToken = launchToken;
     this.launchUrl = launchUrl;
     client = new HttpClient();
     HttpResponseMessage responseMessage = null;
     var _launchData = new LaunchData();
     try
     {
         responseMessage = client.PostAsync(launchUrl + "launch/" + launchToken, null).Result;
     }
     catch (Exception e)
     {
         _launchData.response = e.Message;
     }
     if (responseMessage != null)
     {
         string responseText = responseMessage.Content.ReadAsStringAsync().Result;
         var status = responseMessage.StatusCode;
         string cookies = responseMessage.Headers.GetValues("set-cookie").ElementAt(0);
         var cookieParser = new System.Net.CookieContainer();
         cookieParser.SetCookies(new Uri(launchUrl), cookies);
         CookieCollection parsedCookies = cookieParser.GetCookies(new Uri(launchUrl));
         this.cookie = parsedCookies["connect.sid"];
         try
         {
             LaunchData jsonResponse = JsonConvert.DeserializeObject<LaunchData>(responseText);
             _launchData = jsonResponse;
         }
         catch (Exception e)
         {
             _launchData.response = responseText;
         }
         this.launchData = _launchData;
         return _launchData;
     }
     else
     {
         this.launchData = _launchData;
         return _launchData;
     }
 }