Open Closed

Dynamic HTTP Client does not encode url parameter values #2330


User avatar
0
Denis created

Hi

I have issue with GET endpoint which accepts DateTime as parameter. I have microservices 2 A and B. The endpoint is implemented by A and called by B. For calling I use dynamic HttpApiClient. When DateTime passed to http client as parameter, the DateTime is stringified to string with ToString method. Then the string passed to url parameters pasrt without encoded to url format. That leads, when DaeTime stringified to 'dd/MM/yy hh:mm:ss' format, endpoint is not found because dd MM and yy are parsed as segments of url path.

Is that a bug in http client? I checked ClientProxyUrlBuilder and I think that it should use HttpUtility.UrlEncode for every passed value.ToString() - snippet

  • ABP Framework version: v4.4.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): separate
  • Steps to reproduce the issue:
  1. Create GET endpoint which accepts DateTime as parameter
  2. Reference HttpApiClient project/package in another application or try to use client in the same application with the endpoint
  3. Add call of the endpoint

4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think this is design.

    https://github.com/abpframework/abp/pull/8599

    endpoint is not found because dd MM and yy are parsed as segments of url path.

    Can you share the code of your endpoint?

  • User Avatar
    0
    Denis created

    Sure,

    Controller

    [HttpGet]
    [Route("by-dateTime/{utcDateTime}")]
    public async Task<RecordDto> GetRecordByDateTime(DateTime utcDateTime)
            {
                return await _recordAppService.GetRecordByDateTime(utcDateTime);
            }
    

    Application service

    public async Task<RecordDto> GetRecordByDateTime([DisableDateTimeNormalization] DateTime utcDateTime)
            {
                var record = await _recordRepository.GetAsync(i => i.UtcDateTime == utcDateTime);
    
                return await ObjectMapper.Map<RecordDto>(record);
            }
    

    Microservice A gets call of url path /api/records/by-dateTime/27/12/2021 10:00:00. The format of date time is default format in InvariantCulture used by HttpClient.

    But the issue relates not only to DateTime. It relates to any object which has special symbols in string presentation. For example, if we replace DateTime with string parameter, which value has space symbol inside, then we get problem again, because space can not be used without encoding in url path.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will check and fix that. Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    https://github.com/abpframework/abp/pull/11081/

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38