标签:
七牛的管理接口举例,有兴趣的可以自己来写下七牛的管理demao
//ak,sk需要去七牛后台的秘钥中去拿。
public string delete(string encodeUrl)
{
string AccessToken = "";
Stream outstream = null;
string getUrl = "http://" + "rs.qiniu.com" + "/delete/" + encodeUrl;
//使用HttpWebRequest类的Create方法创建一个请求到uri的对象。
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(getUrl);
//指定请求的方式为Get方式
request.Method = WebRequestMethods.Http.Post;
request.Host = "rs.qiniu.com";
request.ContentType = "application/x-www-form-urlencoded";
AccessToken = GetAccessSign("/delete/" + encodeUrl+"\n");
request.Headers.Add("Authorization", "QBox " + AccessToken);
outstream = request.GetRequestStream();
outstream.Close();
//获取该请求所响应回来的资源,并强转为HttpWebResponse响应对象
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//获取该响应对象的可读流
StreamReader reader = new StreamReader(response.GetResponseStream());
//将流文本读取完成并赋值给str
string str = reader.ReadToEnd();
//关闭响应
response.Close();
return str;
}
private string GetAccessSign(string s)
{
byte[] bytesNewURL = this.MyEncoding.GetBytes(s);
byte[] bytesSK = this.MyEncoding.GetBytes(SK);
System.Security.Cryptography.HMACSHA1 hmac = new System.Security.Cryptography.HMACSHA1(bytesSK);
byte[] digest = hmac.ComputeHash(bytesNewURL);
string sign = Convert.ToBase64String(digest);
sign = sign.Replace(‘+‘, ‘-‘).Replace(‘/‘, ‘_‘);
string FinalURL = AK + ":" + sign;
return FinalURL;
}
这里不做演示,主要是让七牛客户能有自己编写的七牛sdk的能力。可以熟练使用七牛的服务,七牛的大部分服务需要一些有代码能力的程序员去编写使用。
Copyright (c) 2012 qiniu.com
标签:
原文地址:http://blog.csdn.net/guoer9973/article/details/44196677