这个请求有什么问题 (Azure management.azure.com API)

What is wrong with this request (Azure management.azure.com API)

我正在尝试让这个 azure API 工作:

https://docs.microsoft.com/en-us/rest/api/machinelearning/webservices/createorupdate

以下代码运行 GET 请求 return 成功(200 OK 和 return 正文),但对底部完全相同的 uri 的 Put 请求失败并返回 400 "Bad request".

中间的代码基本上只是解开第一个请求的 json 输出,并尝试在相同的 uri 上以 PUT 的输入格式发送相同的未更改数据。

谁能帮我看看为什么会失败?

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
HttpResponseMessage response = await httpClient.GetAsync($"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.MachineLearning/webServices/{serviceName}?api-version=2016-05-01-preview");
var json = await response.Content.ReadAsStringAsync();
var f = JsonConvert.DeserializeObject<WebService>(json);

var requestBody = new RequestBody()
{
    location = f.Location,
    name = f.Name,
    tags = f.Tags,
    properties = f.Properties
};

var jsoncontent = JsonConvert.SerializeObject(requestBody, Formatting.None);
var content = new StringContent(jsoncontent, Encoding.UTF8, "application/json"); //tried simpler things like "{\"location\":\"West Europe\"}" with no result
var response2 = await httpClient.PutAsync($"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.MachineLearning/webServices/{serviceName}?api-version=2016-05-01-preview", content, new JsonMediaTypeFormatter());
// last line returns a 400 bad request only.

然后我使用这个自定义对象;

private class RequestBody
{
    public string location { get; set; }
    public string name { get; set; }
    public WebServiceProperties properties { get; set; }
    public IDictionary<string, string> tags { get; set; }
}

这似乎是那些显而易见的事情之一。

末尾的“, new JsonMediaTypeFormatter()” 片段毁了它。删除它解决了问题,没有它 returns 200 OK。