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數據的唯一行動嗎? –