Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
处理 HttpRequestMessage 时,Content 字段是否始终必须为非空?如果是,那么如果我想发送一个空的身体怎么办?如何指定?
例如,使用 DELETE 或 GET 请求。
它绝对应该允许一个空的内容。正如您非常正确地指出的那样,DELETE 和 GET 从来没有内容主体,并且对于 POST 也没有严格的要求。
我通常使用 HttpClient,并且只使用一个空的 StringContent,例如
var response = _connection.Client.PostAsync(path, new StringContent(string.Empty)).Result;