API method only works locally

  Kiến thức lập trình

I have a method in the API controller which allows you to add numbers, it works correctly when I test with a simulator and start the API locally, however the published API when I test with it I receive a 404 error not found (the login user id and the numbers being the same)

 [HttpPut("UpdateSOSNumber/{userId}/{numbers}")]
 public async Task<IActionResult> UpdateSOSNumber(int userId, string numbers)
 {
     UsersEntity user = await _usersRepository.FindByIdAsync(userId);

     if (user != null)
     {
         user.SOSNumber += (string.IsNullOrEmpty(user.SOSNumber) ? "" : ",") + numbers;

         await _usersRepository.UpdateAsync(user);
         await _usersRepository.SaveAsync();

         return Ok("SOS numbers updated successfully");
     }
     else
         return NotFound("User not found");
 }

  private async Task UpdateSOSNumber(string numbers)
  {
      int loginUserId = Convert.ToInt32(await SecureStorage.Default.GetAsync(AppSettings.UserId));

      using (var httpClient = new HttpClient())
      {
          httpClient.BaseAddress = new Uri(AppSettings.UrlApi);
          var requestUri = $"api/v1/Users/UpdateSOSNumber/{loginUserId}/{numbers}";
          var response = await httpClient.PutAsync(requestUri, null);
      }
  }

LEAVE A COMMENT