[英]WebApi.Hal - HttpPost always send null
使用WebApi.Hal時,HttpPosts出現問題。 我這樣發布:
$.ajax({
type: "POST",
url: "http://localhost/TestWebApi/api/test/test2/",
data: {
"reference": bookingref,
"leadname": leadpax,
"_links": {}
},
contentType: "application/hal+json",
//dataType: "application/hal+json",
success: function(data, status) {
alert("POST: Data: " + data + "\nStatus: " + status);
$("#result").text(JSON.stringify(data, null, 4));
},
error: function(xhr, ajaxOptions, thrownError) {
alert('POST: Status: ' + xhr.status + ', Error Thrown: ' + thrownError);
}
});
並像這樣挑選帖子:
public LoginDetails PostTest2([FromBody]LoginDetails value)
{
return new LoginDetails();
}
LoginDetails繼承自Representation,但值始終為null。 有任何想法嗎?
固定,最初我是這樣安裝Hal格式器的...
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new JsonHalMediaTypeFormatter());
GlobalConfiguration.Configuration.Formatters.Add(new XmlHalMediaTypeFormatter());
我把它改成了這個...
GlobalConfiguration.Configuration.Formatters.Insert(0, new XmlHalMediaTypeFormatter());
GlobalConfiguration.Configuration.Formatters.Insert(0, new JsonHalMediaTypeFormatter());
這樣可以保留舊格式器,但在默認格式器之前插入Hal格式器(為它們提供更高的優先級)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.