为什么为天蓝色数据湖gen2调用put文件api时会丢失标题错误?

时间:2019-02-27 22:08:19

标签: azure azure-data-lake azure-data-factory-2

我试图直接调用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;
}

1 个答案:

答案 0 :(得分:0)

仅回答我自己的问题...我缺少resource = file查询字符串参数。这样可以使请求成功并创建文件。