InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [调用-RestMethod], WebException
InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
我正在测试 Web Core API,但收到 500 内部服务器错误。
我在控制器上的方法是;
[Route("api/property")]
public class PropertyController : BaseSirController
{
[HttpPost("{contractId}/saveproperty")]
public IActionResult SaveProperty(int contractId, [FromBody] PropertyContractDto property)
{
if (property == null)
{
return BadRequest();
}
if (contractId == 0)
{
return NotFound();
}
return Ok();
//return CreatedAtRoute("GetPropertyInspectionsForContract", new {contractId = contractId}, properties);
}
然后在我的 POWershell 命令中输入:
Invoke-RestMethod http://localhost:17972/api/property/7/saveproperty -Method POST -Body (@{UPRN="1244"; StreetName="The Street"; AddressLine2="ALine2"; AddressLine3="ALine3"; AddressLine4="ALine4"; Postcode="N1 7PL"; Latitude="23"; Longitude="77"; BlockUPRN="B1244"; PropertyNo="23"; BlockName="Wenlock Court"; Comments="blah blah blah"; PropertyTypeId="1"; NumberOfBathrooms="1"; NumberOfBedrooms="2"; NumberOfKitchens="1"; PropertyContractId="23"; PropertyType="Maisonette"} | ConvertTo-Json) -ContentType "application/json"
我收到的错误消息是;
Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ Invoke-RestMethod http://localhost:17972/api/property/7/saveproperty -Method POS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我不知道如何解决这个问题。
我发现问题出在我的 Startup.cs、ConfigureServices 方法中。如果我输入 services.AddMvcCore().AddJsonFormatters();
它有效
我正在测试 Web Core API,但收到 500 内部服务器错误。 我在控制器上的方法是;
[Route("api/property")]
public class PropertyController : BaseSirController
{
[HttpPost("{contractId}/saveproperty")]
public IActionResult SaveProperty(int contractId, [FromBody] PropertyContractDto property)
{
if (property == null)
{
return BadRequest();
}
if (contractId == 0)
{
return NotFound();
}
return Ok();
//return CreatedAtRoute("GetPropertyInspectionsForContract", new {contractId = contractId}, properties);
}
然后在我的 POWershell 命令中输入:
Invoke-RestMethod http://localhost:17972/api/property/7/saveproperty -Method POST -Body (@{UPRN="1244"; StreetName="The Street"; AddressLine2="ALine2"; AddressLine3="ALine3"; AddressLine4="ALine4"; Postcode="N1 7PL"; Latitude="23"; Longitude="77"; BlockUPRN="B1244"; PropertyNo="23"; BlockName="Wenlock Court"; Comments="blah blah blah"; PropertyTypeId="1"; NumberOfBathrooms="1"; NumberOfBedrooms="2"; NumberOfKitchens="1"; PropertyContractId="23"; PropertyType="Maisonette"} | ConvertTo-Json) -ContentType "application/json"
我收到的错误消息是;
Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ Invoke-RestMethod http://localhost:17972/api/property/7/saveproperty -Method POS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我不知道如何解决这个问题。
我发现问题出在我的 Startup.cs、ConfigureServices 方法中。如果我输入 services.AddMvcCore().AddJsonFormatters();
它有效