![](/img/trans.png)
[英]AngularJs Post Object with child collections to a MVC WebAPI
[英]Webapi POST results in {object} in MVC Controller
我想post
一個string
到MVC Controller
和結果總是{object}
,我不能夠解析\\解碼\\反序列化。 我怎么能得到那串?
C#:
[HttpPost]
public void Foo(dynamic str)
{
//str always equals to '{object}'
var path = @"C:\cookieParserXmlOutput\";
}
客戶代碼:
then((res:any) => {
let strObj={
str:res.data
};
return this.$http.post("/App/Foo",strObj,{
headers: { "Content-Type": "application/json; charset=utf-8" }
});
}).then((res:any)=>{
return res;
})
如果要在POST
正文中發送object
,則還應該在ASP.NET Endpoint方法中檢索object
。 將您的string str
包裝到一個class
:
public class MyRequest
{
public string Str { get; set; }
}
[HttpPost]
public void Foo(MyRequest request)
{
...
}
將內容類型更改為text/plain
然后使用JSON.stringify
將對象轉換為字符串
return this.$http.post("/App/Foo",JSON.stringify(strObj),{
headers: { "Content-Type": "text/plain; charset=utf-8" }
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.