I have the same problem... ISAPI dont catch the URI for example.
My website work's fine localhost:8077/api for example
But when convert into ISAPI, i cant call "api"
give-me error
My code:
procedure TUniServerModule.UniGUIServerModuleHTTPCommand(
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
var Handled: Boolean);
var
field_name,nomeDaColuna,valorDaColuna : String;
I: Integer;
Resultado:String;
begin
if (ARequestInfo.Params.Values['funcao']<>'sibsref-todos') and
(ARequestInfo.Params.Values['funcao']<>'sibsref-lista') and
(ARequestInfo.Params.Values['funcao']<>'sibsref-insere') then exit;
if ARequestInfo.Params.Values['funcao']='sibsref-todos' then
begin
//showmessage('1');
AResponseInfo.ContentType := 'text/html';
if ARequestInfo.Params.Count<>3 then
begin
AResponseInfo.ContentText:='error 401';
exit;
end;
ZQueryAPI.Close;
ZQueryAPI.SQL.Clear;
ZQueryAPI.SQL.Text :='select sibs_meps1_id as id,sibs_meps1_meps0id as meps0id, sibs_meps1_dthn as data '+
',sibs_meps1_ref as referencia, sibs_meps1_psc as valor'+
' from sibs_meps1 where dataficheiro>=:Data1 and dataficheiro<=:data2';
ZQueryAPI.ParamByName('Data1').AsString:=copy(ARequestInfo.Params.Values['datainicio'],1,10);
ZQueryAPI.ParamByName('Data2').AsString:=copy(ARequestInfo.Params.Values['datafim'],1,10);
ZQueryAPI.Active := True;
ZQueryAPI.First;
end;
if ARequestInfo.Params.ValueFromIndex[0]='sibsref-lista' then
begin
AResponseInfo.ContentType := 'text/html';
if ARequestInfo.Params.Count<>2 then
begin
AResponseInfo.ContentText:='error 402';
exit;
end;
ZQueryAPI.Close;
ZQueryAPI.SQL.Clear;
ZQueryAPI.SQL.Text :='select sibs_meps1_id as id,sibs_meps1_meps0id as meps0id, sibs_meps1_dthn as data '+
',sibs_meps1_ref as referencia, sibs_meps1_psc as valor'+
' from sibs_meps1 where sibs_meps1_ref=:Data1';
ZQueryAPI.ParamByName('Data1').AsString:=copy(ARequestInfo.Params.Values['ref'],1,10);
ZQueryAPI.Active := True;
ZQueryAPI.First;
end;
if ARequestInfo.Params.ValueFromIndex[0]='sibsref-insere' then
begin
AResponseInfo.ContentType := 'text/html';
//showmessage('3');
if ARequestInfo.Params.Count<>8 then
begin
AResponseInfo.ContentText:='error 404';
exit;
end;
ZQueryAPI.Close;
ZQueryAPI.SQL.Clear;
ZQueryAPI.SQL.Text :='DELETE FROM sibs_entidades WHERE CODIGO=:CODIGO';
ZQueryAPI.ParamByName('CODIGO').AsString:=ARequestInfo.Params.Values['codigo'];
ZQueryAPI.ExecSQL;
ZQueryAPI.Close;
ZQueryAPI.SQL.Clear;
ZQueryAPI.SQL.Text :='INSERT INTO sibs_entidades (CODIGO,TELEMOVEL,EMAIL,NOME,APELIDO,ENTTRAB,CARTAO,REFERENCIA) '+
'VALUES (:CODIGO,:TELEMOVEL,:EMAIL,:NOME,:APELIDO,:ENTTRAB,:CARTAO,:REFERENCIA)';
ZQueryAPI.ParamByName('CODIGO').AsString:=ARequestInfo.Params.Values['codigo'];
ZQueryAPI.ParamByName('TELEMOVEL').AsString:=ARequestInfo.Params.Values['telemovel'];
ZQueryAPI.ParamByName('EMAIL').AsString:=ARequestInfo.Params.Values['email'];
ZQueryAPI.ParamByName('NOME').AsString:=ARequestInfo.Params.Values['nome'];
ZQueryAPI.ParamByName('APELIDO').AsString:=ARequestInfo.Params.Values['apelido'];
ZQueryAPI.ParamByName('ENTTRAB').AsString:=ARequestInfo.Params.Values['EntTrab'];
ZQueryAPI.ParamByName('CARTAO').AsString:=ARequestInfo.Params.Values['cartao'];
ZQueryAPI.ParamByName('REFERENCIA').AsString:=ReferenciaMultibanco(ARequestInfo.Params.ValueFromIndex[1],15);
ZQueryAPI.ExecSQL;
ZQueryAPI.Close;
ZQueryAPI.SQL.Clear;
ZQueryAPI.SQL.Text :='select CODIGO,REFERENCIA from sibs_entidades where codigo=:codigo';
ZQueryAPI.ParamByName('codigo').AsString:=ARequestInfo.Params.ValueFromIndex[1];
ZQueryAPI.Active := True;
ZQueryAPI.First;
end;
if ZQueryAPI.IsEmpty then exit;
Resultado := '[';
while (not ZQueryAPI.EOF) do
begin
Resultado := Resultado+'{';
for I := 0 to ZQueryAPI.FieldDefs.Count-1 do
begin
nomeDaColuna := ZQueryAPI.FieldDefs[I].Name;
valorDaColuna := ZQueryAPI.FieldByName(nomeDaColuna).AsString;
Resultado := Resultado+'"'+nomeDaColuna+'":"'+valorDaColuna+'",';
end;
Delete(Resultado, Length(Resultado), 1);
Resultado := Resultado+'},';
ZQueryAPI.Next;
end;
ZQueryAPI.Refresh;
Delete(Resultado, Length(Resultado), 1);
Resultado := Resultado+']';
AResponseInfo.ContentText:=Resultado;
//AResponseInfo.WriteContent;
Handled := true;
//else
// Handled := False;
end;