加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

powershell – InvalidOperation:(System.Net.HttpWebRequest:

发布时间:2020-12-16 03:24:49 所属栏目:asp.Net 来源:网络整理
导读:我正在测试Web Core API,我收到500内部服务器错误. 我控制器上的方法是; [Route("api/property")]public class PropertyController : BaseSirController{ [HttpPost("{contractId}/saveproperty")] public IActionResult SaveProperty(int contractId,[FromB
我正在测试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();有用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读