1
我的控制器无法通过POST
方法接受字符串。什么可能是错的?当我创建HttpClient
像这样发送内容:通过POST发送字符串 - 不支持的媒体类型或空参数
var content = new FormUrlEncodedContent(new []
{
new KeyValuePair<string, string>("signature", "someexamplecontent"),
});
var response = await _client.PostAsync(path, content);
我得到一个错误:415, Unsupported media type
并没有步入控制器。相反,当我使用PostAsJsonAsync
- 进入但参数signature
为空。
var response = await _client.PostAsJsonAsync(path, content);
这是在控制器的方法:
[HttpPost("generatecert")]
public byte[] PostGenerateCertificate([FromBody] string signature)
{
}
您是否检查过请求发送了正确的Content-Type和Content-Encoding标头,并确保服务器接受“application/x-www-form-urlencoded”内容类型?这是您收到POST'ed数据的唯一行动吗? –