I access directly with the browser, and it will report an error.
Let's take a look at what is JsonResult?
JsonResult: JsonResult has a property of type Data that represents the data object that needs to be converted to JSON format. The properties ContentEncoding and ContentType are the encoding methods and media types of the current response settings, and the default media type is application/json.
Remark: For security reasons, JsonResult cannot be used as a response to an HTTP-GET request by default, in which case an InvalidOperationException exception will be thrown directly. We can enable JsonResult support for HTTP-GET requests through its JsonRequestBehavior property. The property type is JsonRequestBehavior enumeration, and the two enums, AllowGet and DenyGet, respectively, indicate allow/deny support for responses to HTTP-GET requests. The JsonRequestBehavior property of JsonResult is set to DenyGet when initialized, and if we need to respond to HTTP-GET requests with the created JsonResult, we need to explicitly set its JsonRequestBehavior property to AllowGet.
Therefore, the reason for the error is the get request we use, everyone understands, just replace it with post
|