Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何从httpc#dotnet获取内容_Asp.net_Post_.net Core - Fatal编程技术网

Asp.net 如何从httpc#dotnet获取内容

Asp.net 如何从httpc#dotnet获取内容,asp.net,post,.net-core,Asp.net,Post,.net Core,我试图将post请求发送到WebApi,但在post方法中找不到httpContent,尽管Get请求中没有问题 在WebApp中 var json = JsonConvert.SerializeObject(new TestClass() { Id="someId"}); var content = new StringContent(json, Encoding.UTF8, "application/json"); var res = await client.GetAsync("http:

我试图将post请求发送到WebApi,但在post方法中找不到httpContent,尽管Get请求中没有问题

在WebApp中

var json = JsonConvert.SerializeObject(new TestClass() { Id="someId"});
var content = new StringContent(json, Encoding.UTF8, "application/json");
var res = await client.GetAsync("http://localhost:00000/home/testGet?username=" + username);
var post = await client.PostAsync("http://localhost:00000/home/testPost?username=" + username, content );
下面是WebApi中的Post请求(我也想绑定模型)


由于HttpContext.Request,内容被传输。ContentLength的变化取决于我给它的json Id。

您可能需要执行以下操作:

[HttpPost]
public ActionResult testPost([FromUri]string username, TestClass testClass)
{
    var t = new TestClass() { Id = "333", Name = "name" };
    return Json(t, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public ActionResult testPost([FromUri]string username, TestClass testClass)
{
    var t = new TestClass() { Id = "333", Name = "name" };
    return Json(t, JsonRequestBehavior.AllowGet);
}