movorack
27-05-2017, 00:06:29
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:
Project raised exception class EEncodingError with message 'No mapping for the Unicode character exists in the target multi-byte code page'.
/////////////////////////////////////////////////////////////////
//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
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.
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:
Project raised exception class EEncodingError with message 'No mapping for the Unicode character exists in the target multi-byte code page'.
/////////////////////////////////////////////////////////////////
//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
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.