-2
I have a method in DELPHI that performs a Post using TIDHTTP
. The first time it works normally, but from the second it presents me the error: exception class EIdHTTPProtocolException with message 'HTTP/1.1 400 Bad Request
the method is like this:
function TApiAPE.postJson(uri: string; sJsonToSend: string): TRetornoAPE;
var JsonToSend: TStringStream;
sResponse: string;
jsonObj: TJSONObject;
begin
result.ok := false;
result.mensagem := '';
result.idRetorno := 0;
JsonToSend := TStringStream.Create( Utf8Encode( sJsonToSend ) );
try
FHTTPClient.Request.Method := 'POST';
try
sResponse := FHTTPClient.Post(uri, JsonToSend); //<<< AQUI ELE APRESENTA O ERRO NA SEGUNDA CHAMADA AO METODO
if FHTTPClient.ResponseCode=200 then
begin
//{
// "MensagemRetorno": "Requisição feita com sucesso",
// "idGerado": 510387
//}
jsonObj := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(sResponse),0) as TJSONObject;
if jsonObj.Get('idGerado')<>nil then
begin
result.ok := true;
result.mensagem := jsonObj.GetValue('MensagemRetorno').Value ;
result.idRetorno := StrToIntDef( jsonObj.GetValue('idGerado').Value,0 );
end;
end;
except
on E: EIdHTTPProtocolException do
begin
result.codigoRetorno := FHTTPClient.ResponseCode;
FHTTPClient.Disconnect;
end;
end;
finally
JsonToSend.free;
end;
end;
Does anyone know what it can be? the contents of the variable sJsonToSend
is the same as the previous
Thanks fellow, following your tip discovered by API requirement need to inform a differentiated ID to each request. Solved
– Elias Conti