作者:蔡彬好看_352 | 来源:互联网 | 2023-09-02 09:36
主机头加上后Authorization: QBox 依旧提示401
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public static bool DeleteImgToQiniu(string url)
{
bool result = false;
Qiniu.Conf.Config.ACCESS_KEY = ACCESSKEY;
Qiniu.Conf.Config.SECRET_KEY = SECRETKEY;
CollectHelper collecthelper = new CollectHelper();
string httpRespOnse= "";
string httpParams= Base64URLSafe.Encode(url.Replace("http://7xromb.com1.z0.glb.clouddn.com/",""));
string httpUrl = "http://rs.qiniu.com/delete/" + httpParams;
string signingStr = "/delete/" + httpParams;
string sign = HmacSha1Sign(signingStr, SECRETKEY);
string encodeBase64 = Base64URLSafe.Encode(sign);
string accessToken = string.Format("Authorization: QBox {0}:{1}", ACCESSKEY, encodeBase64);
httpRespOnse= collecthelper.CollectHtml(httpUrl, httpParams, CollectHelper.Method.POST, CollectHelper.HtmlEncoding.GBK, CollectHelper.HtmlEncoding.UTF8, accessToken);
if (httpRespOnse== "") {
result = true;
}
return result;
}
public static string HmacSha1Sign(string text, string key)
{
Encoding encode = Encoding.GetEncoding("GBK");
byte[] byteData = encode.GetBytes(text);
byte[] byteKey = encode.GetBytes(key);
HMACSHA1 hmac = new HMACSHA1(byteKey);
CryptoStream cs = new CryptoStream(Stream.Null, hmac, CryptoStreamMode.Write);
cs.Write(byteData, 0, byteData.Length);
cs.Close();
return Convert.ToBase64String(hmac.Hash);
} |
1
| collecthelper.CollectHtml(string strHeader) |
//部分代码如下:
1
| request.Headers.Add(strHeader) |
;
请大神快速回复。谢谢