[英]Why Fetch Post request with JSON parameter in the body to ASP.NET Core 3.1 WEB API or MVC Controller does not get anything?
[英]issue connecting RestSharp POST request to web API with ASP.NET Core MVC controller
我在VS2017中有一個ASP.NET核心MVC控制器,我正在嘗試以下列方式發出一個休息請求:
var baseURL = @"http://localhost:44317/";
var client = new RestClient(baseURL);
var request = new RestRequest(@"api/values", Method.POST);
request.AddJsonBody(new Scan
{
sid = scanId.ToString(), scanPath = scansParentPath
});
var response = client.Execute(request);
接收類是:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// POST api/values
[HttpPost]
public void Post([FromBody] Scan value)
{
}
}
}
我得到的響應是超時異常。 這個例外的原因是什么? 我是以不正確的方式實施其余的通話嗎?
您的RestSharp POST請求適合我。 第一步是確認遠程服務器發布操作按預期工作,嘗試使用Fiddler或Postman執行發布請求並調試web api以確認。
或者您可以嘗試延長請求的超時:
request.Timeout = 300000;
問題是連接被標記為SSL。 一旦我刪除了EnableSSL的復選框,一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.