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?
– Caputo
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
– Nelson Lima Tavares