0

I set the Request header in postman as "application/x-www-form-urlencoded", and the format of the Request parameter is Json, but I can't get the value in asp.net core, I currently get request.form.keys.count () ==0 requset.body.length ==0 but requset.contentlength >0

Adam
  • 2,726
  • 1
  • 9
  • 22
LoGan
  • 1
  • 1
  • 1
    Why are you posting JSON and saying it's a form post? That doesn't add up. – CodeCaster Jun 21 '19 at 09:01
  • This is what I encountered. The request header set by the other side is "applicationx-www-form-urlencoded", but the submitted parameters are Json, such as {"a":"a","b":"b"}, – LoGan Jun 21 '19 at 09:28
  • Then kick the other side until they send the proper header/body combination. Or see [Access Raw Request Body](https://stackoverflow.com/questions/31678990/access-raw-request-body) – CodeCaster Jun 21 '19 at 09:36
  • lol,I'd like to, but my boss won't let me – LoGan Jun 21 '19 at 09:48

1 Answers1

0

I found the source of the problem, when I used routing matches like Controller/Action/id, I was unable to read the requested parameters If I don't use it, I can read these parameters, and I suspect that this is a problem with the underlying code, and I can't solve it, so I don't use route matching, and I'm sad when I can't use route matching,I cannot get the requested parameters as follows=>

    [Route("test/{str}")]       
public async Task<IActionResult> test(string str)
{         
    return Content(str);
}
LoGan
  • 1
  • 1