我尝试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;
})
答案 0 :(得分:2)
如果要在POST
正文中发送object
,还应该在ASP.NET端点方法中检索string str
。将您的class
换入public class MyRequest
{
public string Str { get; set; }
}
[HttpPost]
public void Foo(MyRequest request)
{
...
}
:
var number = 4
var percentage = 100 / number
var somaPercentual = new Array();
for (i = 0; i < number; i++) {
var percentage = percentage
somaPercentual.push(percentage)
}
console.log(somaPercentual)
答案 1 :(得分:0)
将内容类型更改为text/plain
,并使用JSON.stringify
将对象转换为字符串
return this.$http.post("/App/Foo",JSON.stringify(strObj),{
headers: { "Content-Type": "text/plain; charset=utf-8" }
});