Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#向azure存储发出http put请求_C#_Azure_Azure Storage - Fatal编程技术网

c#向azure存储发出http put请求

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

嗨,我想知道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);
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);