当前位置: 首页>>代码示例>>C#>>正文


C# Credentials.signRequest方法代码示例

本文整理汇总了C#中Credentials.signRequest方法的典型用法代码示例。如果您正苦于以下问题:C# Credentials.signRequest方法的具体用法?C# Credentials.signRequest怎么用?C# Credentials.signRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Credentials的用法示例。


在下文中一共展示了Credentials.signRequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: snapshot

        public static SnapshotResponse snapshot(Credentials credentials, string streamId, string fileName, string format, long time, string notifyUrl)
        {
            if (streamId == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }

            if (!Utils.isArgNotEmpty(fileName))
            {
                throw new PiliException(MessageConfig.ILLEGAL_FILE_NAME_EXCEPTION_MSG);
            }

            if (!Utils.isArgNotEmpty(format))
            {
                throw new PiliException(MessageConfig.ILLEGAL_FORMAT_EXCEPTION_MSG);
            }

            string urlStr = string.Format("{0}/streams/{1}/snapshot", API_BASE_URL, streamId);
            HttpWebResponse response = null;
            JObject json = new JObject();
            json.Add("name", fileName);
            json.Add("format", format);
            if (time > 0)
            {
                json.Add("time", time);
            }
            if (Utils.isArgNotEmpty(notifyUrl))
            {
                json.Add("notifyUrl", notifyUrl);// optional
            }

            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                byte[] body = json.ToString().GetBytes(Config.UTF8);
                string macToken = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.Method = WebRequestMethods.Http.Post;
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }
            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {

                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string text = reader.ReadToEnd();
                    JObject jsonObj = JObject.Parse(text);
                    return new SnapshotResponse(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:78,代码来源:API.cs

示例2: updateStream

        // Update an exist stream
        public static Stream updateStream(Credentials credentials, string streamId, string publishKey, string publishSecurity, bool disabled)
        {
            JObject json = new JObject();

            if (streamId == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }
            if (Utils.isArgNotEmpty(publishKey))
            {
                json.Add("publishKey", publishKey);
            }
            if (Utils.isArgNotEmpty(publishSecurity))
            {

                json.Add("publishSecurity", publishSecurity);
            }
            json.Add("disabled", disabled);

            string urlStr = string.Format("{0}/streams/{1}", API_BASE_URL, streamId);
            HttpWebResponse response = null;
            try
            {
                Uri url = new Uri(urlStr);
                string jsonobj = JsonConvert.SerializeObject(json);
                byte[] body = jsonobj.ToString().GetBytes(Config.UTF8);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                string macToken = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.Method = WebRequestMethods.Http.Post;
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }

                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {

                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string text = reader.ReadToEnd();
                    JObject jsonObj = JObject.Parse(text);
                    return new Stream(jsonObj, credentials);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:72,代码来源:API.cs

示例3: createStream

        public static Stream createStream(Credentials credentials, string hubName, string title, string publishKey, string publishSecurity)
        {
            //  System.out.println("createStream:" + API_BASE_URL);
            string urlStr = API_BASE_URL + "/streams";
            Console.WriteLine("API_BASE_URL---------" + API_BASE_URL);

            Dictionary<string, string> json = new Dictionary<string, string>();
            json.Add("hub", hubName);
            if (Utils.isArgNotEmpty(title))
            {
                if (title.Length < Config.TITLE_MIN_LENGTH || title.Length > Config.TITLE_MAX_LENGTH)
                {
                    throw new PiliException(MessageConfig.ILLEGAL_TITLE_MSG);
                }
                json.Add("title", title);
            }
            if (Utils.isArgNotEmpty(publishKey))
            {
                json.Add("publishKey", publishKey);
            }
            if (Utils.isArgNotEmpty(publishSecurity))
            {
                json.Add("publishSecurity", publishSecurity);
            }
            HttpWebResponse response = null;
            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                mOkHttpClient.Method = WebRequestMethods.Http.Post;
                string jsonobj = JsonConvert.SerializeObject(json);
                byte[] body = jsonobj.ToString().GetBytes(Config.UTF8);
                string macToken = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }
                response = (HttpWebResponse)mOkHttpClient.GetResponse();

            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string text = reader.ReadToEnd();
                    JObject jsonObj = JObject.Parse(text);
                    return new Stream(jsonObj, credentials);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:75,代码来源:API.cs

示例4: listStreams

        // List stream
        public static StreamList listStreams(Credentials credentials, string hubName, string startMarker, long limitCount, string titlePrefix)
        {
            try
            {
                System.Text.Encoding encoding = System.Text.Encoding.UTF8;

                hubName = System.Web.HttpUtility.UrlEncode(hubName);
                if (Utils.isArgNotEmpty(startMarker))
                {
                    startMarker = System.Web.HttpUtility.UrlEncode(startMarker);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }
            string urlStr = string.Format("{0}/streams?hub={1}", API_BASE_URL, hubName);
            if (Utils.isArgNotEmpty(startMarker))
            {
                urlStr += "&marker=" + startMarker;
            }
            if (limitCount > 0)
            {
                urlStr += "&limit=" + limitCount;
            }
            if (Utils.isArgNotEmpty(titlePrefix))
            {
                urlStr += "&title=" + titlePrefix;
            }
            HttpWebResponse response = null;
            try
            {
                Uri url = new Uri(urlStr);
                string macToken = credentials.signRequest(url, "GET", null, null);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                mOkHttpClient.Method = WebRequestMethods.Http.Get;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string text = reader.ReadToEnd();
                    JObject jsonObj = JObject.Parse(text);
                    return new StreamList(jsonObj, credentials);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:72,代码来源:API.cs

示例5: getStreamStatus

 // get stream status
 public static Status getStreamStatus(Credentials credentials, string streamId)
 {
     if (streamId == null)
     {
         throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
     }
     string urlStr = string.Format("{0}/streams/{1}/status", API_BASE_URL, streamId);
     HttpWebResponse response = null;
     try
     {
         Uri url = new Uri(urlStr);
         mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
         string macToken = credentials.signRequest(url, "GET", null, null);
         mOkHttpClient.Method = WebRequestMethods.Http.Get;
         mOkHttpClient.UserAgent = Utils.UserAgent;
         mOkHttpClient.Headers.Add("Authorization", macToken);
         response = (HttpWebResponse)mOkHttpClient.GetResponse();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
         throw new PiliException(e);
     }
     // response never be null
     if ((int)response.StatusCode == 200)
     {
         try
         {
             StreamReader reader = new StreamReader(response.GetResponseStream());
             string text = reader.ReadToEnd();
             JObject jsonObj = JObject.Parse(text);
             return new Status(jsonObj);
         }
         catch (IOException e)
         {
             Console.WriteLine(e.ToString());
             Console.Write(e.StackTrace);
             throw new PiliException(e);
         }
     }
     else
     {
         throw new PiliException(response);
     }
 }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:47,代码来源:API.cs

示例6: getStreamSegments

        // Get recording segments from an exist stream
        public static SegmentList getStreamSegments(Credentials credentials, string streamId, long startTime, long endTime, int limitCount)
        {
            if (streamId == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }
            string urlStr = string.Format("{0}/streams/{1}/segments", API_BASE_URL, streamId);
            if (startTime > 0 && endTime > 0 && startTime < endTime)
            {
                urlStr += "?start=" + startTime + "&end=" + endTime;
            }
            if (limitCount > 0)
            {
                urlStr += "&limit=" + limitCount;
            }
            HttpWebResponse response = null;
            try
            {
                Uri url = new Uri(urlStr);
                string macToken = credentials.signRequest(url, "GET", null, null);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                mOkHttpClient.Method = WebRequestMethods.Http.Get;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                response = (HttpWebResponse)mOkHttpClient.GetResponse();

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string text = reader.ReadToEnd();
                    JObject jsonObj = JObject.Parse(text);
                    if (string.IsNullOrEmpty(jsonObj["segments"].ToString()))
                    {
                        throw new PiliException("Segments is null");
                    }
                    return new SegmentList(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:61,代码来源:API.cs

示例7: deleteStream

        // Delete stream
        public static string deleteStream(Credentials credentials, string streamId)
        {
            if (streamId == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }

            string urlStr = string.Format("{0}/streams/{1}", API_BASE_URL, streamId);
            HttpWebResponse response = null;
            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string macToken = credentials.signRequest(url, "DELETE", null, null);
                mOkHttpClient.Method = "DELETE";
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                Console.WriteLine(macToken);
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode/100 == 2)
            {
                string text = "No Content";
                return text;
            }
            else
            {
                throw new PiliException(response);
            }
        }
开发者ID:pili-engineering,项目名称:pili-sdk-csharp,代码行数:39,代码来源:API.cs


注:本文中的Credentials.signRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。