请教七牛处理结果持久化的问题

报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;
        }
    }
阅读 2.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
七牛云问答
子站问答
访问
宣传栏