0
votes

I have few c# APIs Post and Get method calling to MSSQL database. I created a copy of the database and copy of those API with 2nd connection string - referring to the new database.

In native postman , calls to old APIs work fine, and I get the result 200, but calls to the new APIs keep returning status 400 and response body start with: "System.NullReferenceException" In chrome postman, all APIs (old and new) work fine.

It appear that the payload (body x-www-form-urlencoded) parameters don't forward into the inputs class in native postman.

Request Header: [{"key":"Content-Type","value":"application/x-www-form-urlencoded","description":""}]

Request Body x-www-form-urlencoded:

[{"key":"Entranceref","value":"25","description":""},{"key":"Primaryid","value":"1234","description":""},{"key":"Secondaryid","value":"1234","description":""},{"key":"Loginip","value":"1.1.1.1","description":""},{"key":"Useragent","value":"dfgffd","description":""},{"key":"Registrar","value":"0","description":""},{"key":"Cookieid","value":"rtyu","description":""},{"key":"Cookiecount","value":"1","description":""},{"key":"Languageid","value":"he","description":""}]

Status - 400 Bad request

Response Body:

"ClassName": "System.NullReferenceException", "Message": "Object reference not set to an instance of an object.", "Data": null,

This is the API input class

      public class MdCheckEvent
     {
      public string Entranceref { get; set; }
        public string Primaryid { get; set; }
        public string Secondaryid { get; set; }
        public string Loginip { get; set; }
        public string Useragent { get; set; }
        public int Registrar { get; set; }
        public string Cookieid { get; set; }
        public int Cookiecount { get; set; }
        public string Languageid { get; set; }
    }
    [HttpPost public HttpResponseMessage PostCheckEnterance([FromBody] MdCheckEvent Inputs)
1

1 Answers

0
votes

Solved the problem:

Written the params from scratch - solved it. It was missed the type and enabled definitions per each parameter.

Weird thing it effectes only in native version.

Now the payload look like this:

[{"key":"Entranceref","value":"25","description":"","type":"text","enabled":true},{"key":"Primaryid","value":"1234","description":"","type":"text","enabled":true},{"key":"Secondaryid","value":"1234","description":"","type":"text","enabled":true},{"key":"Loginip","value":"1.1.1.1","description":"","type":"text","enabled":true},{"key":"Useragent","value":"1313sdasd","description":"","type":"text","enabled":true},{"key":"Registrar","value":"1","description":"","type":"text","enabled":true},{"key":"Cookieid","value":"121ss","description":"","type":"text","enabled":true},{"key":"Cookiecount","value":"1","description":"","type":"text","enabled":true},{"key":"Languageid","value":"he","description":"","type":"text","enabled":true}]