1
Good staff I would like to send data by json to a php server from Delphi, I tried to do this way:
Delphi Cliente:
procedure TForm7.Button7Click(Sender: TObject);
var
code : Integer;
sResponse : String;
Json : String;
JsonToSend : TStringStream;
begin
Json := '{"email" : "[email protected]", "password" : "123testar"}';
JsonToSend := TStringStream.Create( UTF8Encode(Json) );
try
IdHTTP1.Request.Method := 'POST';
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.ContentEncoding := 'utf-8';
try
sResponse := IdHTTP1.Post('http://localhost/webservice/receber.php', JsonToSend);
except
on E: Exception do
begin
Memo1.Lines.Add('Error on request: '#13#10 + e.Message);
Exit;
end;
end;
Memo1.lines.clear;
Memo1.lines.add(sResponse);
finally
JsonToSend.Free();
end;
end;
PHP server:
<?php
$jason_data = file_get_contents('http://localhost/webservice/receber.php');
$decoded_data = json_decode($json_data);
print_r($decoded_data);
?>
But I didn’t succeed, Someone would know how to make it work?