Datasnap error with Indy

Asked

Viewed 2,202 times

4

I made a server application that calling the methods by Browse, everything works perfect, but to test my methods I built a client using TdHTTP and I call the methods as follows:

procedure TF_CLIENTE.SBEnviar2Click(Sender: TObject);
var Url        : String;
    lJSO       : String;
    jsonToSend : TStringStream;
begin

  Url := 'http://localhost:809...ecomandoPOST/';

  lJSO                                    := ('{"name":"TESTE"}');
  jsonToSend                              := TStringStream.Create(lJSO,TEncoding.UTF8);

  idHttp.ProxyParams.Clear;
  idHttp.ProxyParams.BasicAuthentication  := false;
  idHttp.Request.BasicAuthentication      := True;
  idHttp.Request.Accept                   := 'text/javascript';
  IdHTTP.Request.ContentType              := 'application/json';
  IdHTTP.Request.ContentEncoding          := 'utf-8';
  idHttp.Request.Method                   := 'POST';
  IdHTTP.Request.BasicAuthentication      := True;
  IdHTTP.Request.Authentication           := TIdBasicAuthentication.Create;
  IdHttp.Request.Authentication.Username  := 'USUARIO';
  IdHttp.Request.Authentication.password  := 'SENHA';
  IdHttp.Request.ContentLength            := Length(lJSO);
  try
    Memo1.Text := idHttp.Post(Url,jsonToSend);
  except
    on E : Exception do
      begin
        Memo1.Lines.Add('Exception class name = '+E.ClassName);
        Memo1.Lines.Add('Exception message = '+E.Message);
      end;
  end;

end;

I’ve already released the Dispatch:

procedure TF_WebModule.WebModuleBeforeDispatch(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  Response.SetCustomHeader('access-control-allow-origin','*');
  Response.SetCustomHeader('access-control-allow-Methods','PUT, POST, GET, DELETE');
  Response.SetCustomHeader('access-control-allow-Headers','accept, authorization, origin');
  if FServerFunctionInvokerAction <> nil then
  FServerFunctionInvokerAction.Enabled := AllowServerFunctionInvoker;
end;

I already saw the user and Indy’s authentication comes:

procedure TF_WebModule.DSAuthenticationManager1UserAuthenticate(Sender: TObject;
  const Protocol, Context, User, Password: string; var valid: Boolean;
  UserRoles: TStrings);
begin

  if Request.Method = 'OPTIONS' then
    valid := False
  else
    if ((User = 'USUARIO') and (Password = 'SENHA')) then
      valid := True
    else
      valid := False;

end;

It presents an error:

Exception class name = Eidhttpprotocolexception Exception message = HTTP/1.1 500 Internal Server Error

  • Hello Appeared, the HTTP 500 error indicates that an error has occurred on the server. If you are debugging the server no exception occurs?

  • There is a rule for training the URI following the link q must be the basis: http://docwiki.embarcadero.com/RADStudio/XE8/en/DataSnap_REST

1 answer

-1

  • 1

    This does not provide an answer to the question. To criticize or ask for clarification from an author, leave a comment below its publication - you can always comment on your own publications and when you have reputation points enough you will be able comment on any publication.

  • The cause of the error may be the URL itself, @rray.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.