本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}