嗨我想知道如果 azure blob 服务 api http://msdn.microsoft.com/en-us/library/dd135733.aspx
可以使用c#调用。我想上传一个文件,例如一个word文档到一个存储位置,http方法是“put”,其余的url是
“ http://myaccount.blob.core.windows.net/mycontainer/myblob ”
这段代码会起作用吗?
string username = "user";
string password = "password";
string data = "path to word document;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "PUT";
request.Credentials = new NetworkCredential(username, password);
request.ContentLength = data.Length;
request.ContentType = "text/plain";
using (StreamWriter writer = new StreamWriter(request.GetRequestStream( ))) {
writer.WriteLine(data);
}
WebResponse response = request.GetResponse( );
using (StreamReader reader = new StreamReader(response.GetResponseStream( ))) {
while (reader.Peek( ) != -1) {
Console.WriteLine(reader.ReadLine( ));