我有程序,该程序在不同的解决方案中调用API。当我在localhost上托管API时(VS调试时),一切正常。但是,当我在服务器上发布API项目并尝试从客户端应用程序对其调用POST方法时,出现了404错误。同时,当我在此端点上调用其他方法(GET,PUT等)时,所有方法都起作用。只有POST在服务器上不起作用。
我在Postman中检查了URL,并且POST方法在Postman中工作正常。
在客户端应用中,调用代码如下:
HttpResponseMessage response = await client.PostAsync("URL_HERE", element, jsonformatter);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// code removed
}
else
{
// code removed
}
这是我得到的答复:
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Pragma: no-cache
Transfer-Encoding: chunked
Strict-Transport-Security: max-age=2592000
Cache-Control: no-cache
Date: Wed, 01 Apr 2020 07:20:48 GMT
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Expires: -1
}}
在本地主机上托管API时响应(或从Postman调用服务器上托管的API):
{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Date: Wed, 01 Apr 2020 08:23:53 GMT
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
}}
API中的代码:
[HttpPost]
public async Task<ActionResult<ElementType>> Post([FromBody] ElementType Element)
{
//code removed
}
我检查了SSL是否存在问题,我在服务器和项目上将其打开/关闭,但没有更改。