c#向azure存储发出http put请求
嗨,我想知道azure blob服务api 可以使用c#调用。我想上传一个文件,例如一个word文档到一个存储位置,http方法是“put”,其余url是 “” 这个代码行吗c#向azure存储发出http put请求,c#,azure,azure-storage,C#,Azure,Azure Storage,嗨,我想知道azure blob服务api 可以使用c#调用。我想上传一个文件,例如一个word文档到一个存储位置,http方法是“put”,其余url是 “” 这个代码行吗 string username = "user"; string password = "password"; string data = "path to word document; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); re
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( ));
不,这样不行。对Windows Azure存储的身份验证涉及对请求的标头进行签名。(见附件。) 请注意,SDK附带的.NET StorageClient库是可再发行的,因此您只需添加对该库的引用即可(从内存中)执行以下操作:
CloudStorageAccount.Parse(“”)
.CreateCloudBlobClient()
.GetBlobReference(“mycontainer/myblob”)
.UploadByteArray(数据);
不,这样不行。对Windows Azure存储的身份验证涉及对请求的标头进行签名。(见附件。)
请注意,SDK附带的.NET StorageClient库是可再发行的,因此您只需添加对该库的引用即可(从内存中)执行以下操作:
CloudStorageAccount.Parse(“”)
.CreateCloudBlobClient()
.GetBlobReference(“mycontainer/myblob”)
.UploadByteArray(数据);
CloudStorageAccount.Parse("<connection string>")
.CreateCloudBlobClient()
.GetBlobReference("mycontainer/myblob")
.UploadByteArray(data);