I'm simply having no luck sending an url encoded form value from postman to a vanilla asp.net core 2.1 web api created with file->new project. I do nothing to it whatsoever but still the new model validation feature seems to kick in and returns a 400 Bad Request to postman. Can anyone tell me what I'm doing wrong?
Controller Action:
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
Raw request (as seen in fiddler):
POST http://localhost:60843/api/values HTTP/1.1
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: a791eee7-63ff-4106-926f-2s67a8dcf37f
User-Agent: PostmanRuntime/7.3.0
Accept: */*
Host: localhost:60843
accept-encoding: gzip, deflate
content-length: 7
Connection: keep-alive
value=test
Raw response:
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Server: Kestrel
X-SourceFiles: =?UTF-8?BQzpcUmVwb3NcVGVzdGJlZFxNb2RlbEJpbmRpbmdcTW9kZWxCaW5kaW5nXGFwaVx2YWx1ZXM=?=
X-Powered-By: ASP.NET
Date: Thu, 25 Oct 2018 15:23:49 GMT
21
{"":["The input was not valid."]}
0
Note again that this is the default template for asp.net web api in Visual Studio 2017.
An interesting fact is that if I add Swashbuckle and go to the swagger ui endpoint and use the built in "try it" functionality it produces an error as well, out of the box.
I've gotten this to work with a complex type and a json body, but I can not get the simple type to work and I've tried with all sorts of different content-types.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…