Esempio n. 1
0
        public static string SendRequest(HttpRequestUtility.RequestEntity req)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(req.Url);

            httpWebRequest.Headers.Clear();
            if (!string.IsNullOrEmpty(req.ProxyIp))
            {
                httpWebRequest.Proxy = new WebProxy(req.ProxyIp);
            }
            if (req.Credential != null)
            {
                httpWebRequest.Credentials = req.Credential;
            }
            httpWebRequest.UserAgent = "PlayfeedSDK V100";
            httpWebRequest.Method    = req.RequestType;
            if (req.ContentType != null)
            {
                httpWebRequest.ContentType = req.ContentType;
            }
            if (req.RequestData != null)
            {
                httpWebRequest.ContentLength = (long)req.RequestData.Length;
                using (Stream requestStream = httpWebRequest.GetRequestStream())
                {
                    requestStream.Write(req.RequestData, 0, req.RequestData.Length);
                }
            }
            string result;

            try
            {
                using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                {
                    using (Stream responseStream = httpWebResponse.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(responseStream))
                        {
                            result = streamReader.ReadToEnd();
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                using (Stream responseStream = ex.Response.GetResponseStream())
                {
                    using (StreamReader streamReader = new StreamReader(responseStream))
                    {
                        result = streamReader.ReadToEnd();
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
 public static string Get(HttpRequestUtility.RequestEntity req)
 {
     return(HttpRequestUtility.SendRequest(req));
 }