//파트너 포인트충전 팝업 URL
        public string getPartnerURL(string BearerToken, string ServiceID, string TOGO, bool UseStaticIP, bool UseGAIP)
        {
            if (string.IsNullOrEmpty(ServiceID))
            {
                throw new LinkhubException(-99999999, "ServiceID is Not entered");
            }
            if (string.IsNullOrEmpty(BearerToken))
            {
                throw new LinkhubException(-99999999, "BearerToken is Not entered");
            }

            string         URI     = getTargetURL(UseStaticIP, UseGAIP) + "/" + ServiceID + "/URL?TG=" + TOGO;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);

            if (this._ProxyYN == true)
            {
                WebProxy proxyRequest = new WebProxy();

                Uri proxyURI = new Uri(this._ProxyAddress);
                proxyRequest.Address     = proxyURI;
                proxyRequest.Credentials = new NetworkCredential(this._ProxyUserName, this._ProxyPassword);
                request.Proxy            = proxyRequest;
            }


            request.Headers.Add("Authorization", "Bearer" + " " + BearerToken);
            request.Method = "GET";

            try
            {
                HttpWebResponse            response   = (HttpWebResponse)request.GetResponse();
                Stream                     stReadData = response.GetResponseStream();
                DataContractJsonSerializer ser2       = new DataContractJsonSerializer(typeof(URLResult));
                URLResult                  result     = (URLResult)ser2.ReadObject(stReadData);

                return(result.url);
            }
            catch (WebException we)
            {
                if (we.Response != null)
                {
                    Stream stReadData = we.Response.GetResponseStream();
                    DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Error));
                    Error t = (Error)ser2.ReadObject(stReadData);
                    throw new LinkhubException(t.code, t.message);
                }

                throw new LinkhubException(-99999999, we.Message);
            }
        }
Esempio n. 2
0
        public String getPartnerURL(String BearerToken, String ServiceID, String TOGO, bool UseStaticIP, bool UseGAIP)
        {
            String URL = getTargetURL(UseStaticIP, UseGAIP);

            String URI = URL + "/" + ServiceID + "/URL?TG=" + TOGO;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);

            request.Headers.Add("Authorization", "Bearer" + " " + BearerToken);

            request.Method = "GET";

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream stReadData = response.GetResponseStream();

                DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(URLResult));

                URLResult result = (URLResult)ser2.ReadObject(stReadData);

                return(result.url);
            }
            catch (WebException we)
            {
                if (we.Response != null)
                {
                    Stream stReadData = we.Response.GetResponseStream();

                    DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(Error));

                    Error t = (Error)ser2.ReadObject(stReadData);

                    throw new LinkhubException(t.code, t.message);
                }

                throw new LinkhubException(-99999999, we.Message);
            }
        }
Esempio n. 3
0
        }        //

        #endregion

        #region HTTP Request Helpers

        public static URLResult GetHttpData(string url, bool getFromCacheIfPossible = true, bool addToCache = true, int cacheMinutes = 30)
        {
            var data = ( URLResult )MemoryCache.Default[url];

            if (data == null || !getFromCacheIfPossible)
            {
                data = new URLResult();
                try
                {
                    var rawResult = new HttpClient().GetAsync(url).Result;

                    data.IsSuccessStatusCode = rawResult.IsSuccessStatusCode;
                    data.ReasonPhrase        = rawResult.ReasonPhrase ?? "";
                    data.StatusCode          = rawResult.StatusCode.ToString();

                    if (rawResult.IsSuccessStatusCode)
                    {
                        data.Content = rawResult.Content.ReadAsStringAsync().Result;
                    }

                    if (addToCache)
                    {
                        MemoryCache.Default.Remove(url);
                        MemoryCache.Default.Add(url, data, DateTime.Now.AddMinutes(cacheMinutes));
                    }
                }
                catch (Exception ex)
                {
                    return(new URLResult()
                    {
                        Content = null,
                        IsSuccessStatusCode = false,
                        ReasonPhrase = ex.Message,
                        StatusCode = "999"
                    });
                }
            }
            return(data);
        }