【问题标题】:Angular http://localhost/BTSWEBVCCAdmin3.0/api/v1/ViewTicketPhotos/GetPhotos?iInstanceID=6992609 404 (Not Found)Angular http://localhost/BTSWEBVCCAdmin3.0/api/v1/ViewTicketPhotos/GetPhotos?iInstanceID=6992609 404(未找到)
【发布时间】:2020-08-22 06:27:39
【问题描述】:

我收到一个 HTTP 失败响应,我不明白为什么,因为 api 正在工作,我检查了 swagger/curl,它不是我的第一个服务,所有其他服务都工作正常

角度服务:

export class TicketPhotosService {

 constructor(private http: HttpClient) { }



getTicketPhotos(iInstanceID: string): Observable<TicketPhoto[]> {
return this.http.get<TicketPhoto[]>(`${environment.url}api/v1/ViewTicketPhotos/GetPhotos`,
 { withCredentials: true, responseType: 'json',
 params: {
  iInstanceID
 }})
 .pipe(
  catchError((err, caught) => {
    throw ErrorResponseUtil.build(err);
  })
);
}

控制器:

[Route("api/v1/[controller]")]
[ApiController]
public class ViewTicketPhotosConrtoller : BTSWebVCCAdminBaseController
{

    IBALVccDefinitions _balVccDefinition;
    private IHostingEnvironment _hostingEnvironment;

    public ViewTicketPhotosConrtoller(IHttpContextAccessor contextAccessor, ISetting setting, ISecurity security, ILogging logging, IBal bal, IBalEmployee balEmployee, IBALVccDefinitions balVccDefinition, IWeb web, IDotNet dotNet, IDistributedCache distributedCache, ICache cache, IText text, IViewRender viewRenderService, IHostingEnvironment hostingEnvironment) 
        : base(contextAccessor, setting, security, logging, bal, balEmployee, web, dotNet, distributedCache, cache, text, viewRenderService, hostingEnvironment)
    {
        _balVccDefinition = balVccDefinition;
        _hostingEnvironment = hostingEnvironment;
    }




    [HttpGet("GetPhotos")]
    [BTSFilter(useMaintenanceFilter: true, useAuthentificationFilter: true, useCultureFilter: true, useLogAccessFilter: true, useSessionExpiredFilter: true, usePermissionApplicationFilter: false, usePermissionOptionFilter: true)]
    [EnableCors]
    public async Task<IActionResult> Get(string iInstanceID)
    {
        try
        {
            return Ok(GetImagePath(_balVccDefinition.GetImagesByQuestionnaireInstanceID(iInstanceID)));
        }
        catch (Exception ex)
        {
            var error = Logging.LogErrorWeb(ex, HttpContext);
            return StatusCode(StatusCodes.Status500InternalServerError, new { error, message = "" });
        }
    }

图片来自 curl

【问题讨论】:

    标签: angular http .net-core service http-status-code-404


    【解决方案1】:

    在您的 Swagger 请求中,您有 .../ViewTicketPhotosConrtoller/...,而 Angular 服务只是 .../ViewTicketPhotos/...

    【讨论】:

      【解决方案2】:

      它实际上是我写错的名称控制器 :( 谢谢 -

      【讨论】:

        猜你喜欢
        • 2017-09-23
        • 2021-03-11
        • 2018-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-04
        • 2022-09-28
        • 2017-03-03
        相关资源
        最近更新 更多