首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],WebException

InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],WebException
EN

Stack Overflow用户
提问于 2017-06-16 16:17:16
回答 1查看 5.7K关注 0票数 6

我正在测试一个Web,我得到了一个500个内部服务器错误。我对我的控制器的方法是;

代码语言:javascript
复制
[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命令中输入:

代码语言:javascript
复制
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"

我得到的错误信息是;

代码语言:javascript
复制
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

我想不出怎么解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-23 08:26:56

我发现问题出在我的Startup.cs,ConfigureServices方法中。如果我把services.AddMvcCore().AddJsonFormatters();放进去,它就能工作

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44593752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档