简体   繁体   中英

Swagger UI unable to show proper response from ASP.net Core WebAPI

I am working with ASP.net Core WebAPI and to produced API documentation I am using Swagger. Swagger successfully generate colourful documentation. But when I try to execute an api method. Always got bellow error from Swagger.

{ "error": "no response from server" }

Api Method

[Route("api/[controller]")]
[Produces("application/json")]
public sealed class AuthController : BaseApiController
{
   [HttpGet]
   [Route("GetByUser/{uid}/{pwd}")]
   public IActionResult GetByUser(string uid, string pwd){....}
 }

Note:

  • I always got correct api response from above method via Browser / Fiddler ( without using Swagger )
  • I also configure CORS in api end. But from Swagger still not getting proper response.

Swagger AppSettings

 "Swagger": {
    "FileName": "ApiDoument.xml",
    "host": "localhost:63687"

  }

Swagger Response

Curl

X GET 'http://localhost:63687/api/Auth/GetByUser/test%40gmail.com/1234'

Request URL

http://localhost:63687/api/Auth/GetByUser/test%40gmail.com/1234

Response Body

no content

Response Code

0

Response Headers

{ "error": "no response from server" }

Problem is resolve, above described error due to bellow Hash value. Swagger unable to return this type of value.

AQAAAAEAACcXdXU4rzH9EpRzS2smaRdvesNxkOQMvKld2ySuzXTNcd+1Gux6CJfV90w==

Solution:

using Newtonsoft.Json;

JsonConvert.SerializeObject(Hashvalue);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM