Ver Mensaje Individual
  #1  
Antiguo 27-05-2017
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Reputación: 20
movorack Va camino a la famamovorack Va camino a la fama
(TRESTRequest) Error al obtener PDF adjunto (Berlin)

Hola a todos.

Estoy tratando de descargar un PDF usando REST (TRESTClient, TRESTRequest y TRESTResponse).

Al ejecutar la solicitud, va hasta el recurso en la plataforma donde está la API y lo descarga, pero no lo muestra ya que genera el error:

Cita:
Project raised exception class EEncodingError with message 'No mapping for the Unicode character exists in the target multi-byte code page'.
Código Delphi [-]
/////////////////////////////////////////////////////////////////
//unit System.Net.HTTPClient

function THTTPResponse.ContentAsString(const AnEncoding: TEncoding): string;
begin
//Linea 2160
    try
      LReader.CopyFrom(LStream, 0); //Aquí el tamaño del stream es de 364510 bytes, lo que es correcto
      Result := LReader.DataString; //Esto llama SysUtils.GetString
    finally
      if LFreeLStream then
       LStream.Free;
    end;
end;

/////////////////////////////////////////////////////////////////
//unit System.SysUtils

function TEncoding.GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): string;
var
  Len: Integer;
begin
//Linea 31441
  Len := GetCharCount(Bytes, ByteIndex, ByteCount); //El resultado de Len es 0
  if (ByteCount > 0) and (Len = 0) then
    raise EEncodingError.CreateRes(@SNoMappingForUnicodeCharacter); //Aquí genera el error
  SetLength(Result, Len);
  GetChars(@Bytes[ByteIndex], ByteCount, PChar(Result), Len);
end;

Estos son los componentes con los parámetros básicos de la solicitud
Código Delphi [-]
object RESTClient1: TRESTClient
  Accept = '*/*'
  AcceptCharset = 'UTF-8, *;q=0.8'
  AcceptEncoding = 'deflate, gzip'
  BaseURL = 'https://...'
  ContentType = 'application/octet-stream'
  Params = <>
  HandleRedirects = True
  RaiseExceptionOn500 = False
end
object RESTRequest1: TRESTRequest
  Accept = '*/*'
  AcceptEncoding = 'deflate, gzip'
  Client = RESTClient1
  Params = <
    item
      Kind = pkHTTPHEADER
      name = 'X-Who'
      Value = '...'
    end
    item
      Kind = pkHTTPHEADER
      name = 'Authorization'
      Options = [poDoNotEncode]
      Value = '...'
    end>
  Resource = 'Documents/LDF/RepresentacionGrafica/Binario'
  Response = RESTResponse1
  SynchronizedEvents = False
end
object RESTResponse1: TRESTResponse
  ContentType = 'application/octet-stream'
  ContentEncoding = 'deflate, gzip'
end

como muestro en la info que adjunto, he estado revisando algunas cosas pero debe ser que ya es viernes a las 17:05 o que la gripe me esta afectando. Pero no doy con la forma de obtener este PDF. (Desde un cliente REST de escritorio si funciona)

De ante mano muchas gracias por cualquier guía que me puedan dar.
__________________
Buena caza y buen remar... http://mivaler.blogspot.com
Responder Con Cita