Я создал ASP.NET Core API и определил свой контроллер следующим образом:
[Route("api/[controller]")]
[ApiController]
public class SignUpController : ControllerBase
{
private readonly DNNContext _context;
public SignUpController(DNNContext context)
{
_context = context;
var merchantSignUpResponse = PutResponse();
}
[HttpPut("{id}")]
public async Task<IActionResult> PutResultAsync(int id, [FromBody]ProPaySignUp signUp)
{
try
{
await _context.SignUpResponses.AddAsync(PutResponse());
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return Accepted();
}
public SignupResponse PutResponse()
{
string url = "https://xmltest.propay.com/api/propayapi/";
var credentials = GetCredentials();
var request = BuildMerchantData();
var restRequest = CreateRestRequest("/Signup", Method.PUT);
restRequest.AddJsonBody(request);
return Execute<SignupResponse>(restRequest, url);
}
private static RestRequest CreateRestRequest(string resource, Method method)
{
var credentials = GetCredentials();
var restRequest = new RestRequest
{
Resource = resource,
Method = method,
RequestFormat = DataFormat.Json,
};
restRequest.AddHeader("accept", "application/json");
restRequest.AddHeader("Authorization", credentials);
return restRequest;
}
private static T Execute<T>(IRestRequest request, string baseUrl) where T : class, new()
{
var client = new RestClient(baseUrl);
var response = client.Execute<T>(request);
if (response.ErrorException != null)
{
Console.WriteLine(
"Error: Exception: {0}, Headers: {1}, Content: {2}, Status Code: {3}",
response.ErrorException,
response.Headers,
response.Content,
response.StatusCode);
}
return response.Data;
}
Решение успешно собирается.Затем я запускаю Почтальон и ввожу URL https://localhost:44381/api/SignUp
методом PUT.Я получаю сообщение о том, что There was an error connecting to https://localhost:44381/api/SignUp.
Затем я открыл командную строку в каталоге, в котором находится мой проект и выполнил dotnet run SOBProPayService
.Возвращенная ошибка:
error NU1605: Detected package downgrade: Microsoft.AspNetCore.Razor.Design from 2.2.0 to 2.1.2. Reference the package directly from the project to select a different version.
Как мне устранить эту ошибку?