报400错误,复制URL到浏览器中打开正常
string saveas = "cjuserhead:111aaa.jpg";
saveas = Qiniu.Util.Base64URLSafe.Encode(saveas);
string tosign = "cjuserhead.qiniudn.com/11.jpg?imageView2/1/w/200/h/200|saveas/" + saveas;
HMACSHA1 sha1 = new HMACSHA1(Encoding.UTF8.GetBytes(sk));
string sign = Qiniu.Util.Base64URLSafe.Encode(sha1.ComputeHash(Encoding.UTF8.GetBytes(tosign)));
string url = "http://cjuserhead.qiniudn.com/11.jpg?imageView2/1/w/200/h/200|saveas/" + saveas + "/sign/" + ak + ":" + sign;
string r = WebRequest(url, "get", 20000, "");
public static string WebRequest(string url, string method, int timeout, string poststr)
{
try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = method;
req.Timeout = timeout;
if (method.ToLower() == "post")
{
Stream postStream = req.GetRequestStream();
byte[] postBytes = Encoding.UTF8.GetBytes(poststr);
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Flush();
postStream.Close();
}
HttpWebResponse response = req.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(responseStream);
string result = sr.ReadToEnd();
sr.Close();
responseStream.Close();
return result;
}
catch(Exception EX)
{
Console.WriteLine(EX.Message + "}}" + EX.StackTrace);
return string.Empty;
}
}