我试图直接调用gen2 rest端点,并不断收到错误消息,提示我缺少必需的标头(MissingRequiredHeader消息未指定此请求必需的HTTP标头。我看不到缺少的标头。正在使用以下代码发送请求。
var client = new HttpClient();
client.BaseAddress = new Uri($"https://{account}.dfs.core.windows.net/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("api_version", "2018-11-09");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authResult.AccessToken);
string azPath = $"{baseRawSystemPath}/{path.Replace("\\", "/")}";
byte[] bytes = Encoding.UTF8.GetBytes(content);
HttpContent body = new StringContent(content, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PutAsync(azPath, body);
if (response.IsSuccessStatusCode)
{
var responseListingJson = await response.Content.ReadAsStringAsync();
return;
}
else
{
var error = await response.Content.ReadAsStringAsync();
return;
}
答案 0 :(得分:0)
仅回答我自己的问题...我缺少resource = file查询字符串参数。这样可以使请求成功并创建文件。