Hi everyone,
I'm stuck a bit, and hope somebody can assist me. Thanks in advance.
I need to get JSON doc from remote server via HTTPS, so I've prepared simple code to get it which is working good on my Windows running PC, nevertheless when I'm trying to get it work on my Android application it's breaking with exception "Hostname resolution for '%hostname%' failed". My assumption that the problem is in HTTPS connection itself, while HTTP execution not leading to error. So my question, is there any way to get it work.
uses
fphttpclient, fpopenssl, openssl;
...
function GetReceipt:string;
var
counter,APos:integer;
AStream:TStream;
AUID:string;
begin
AUID:='';
AStream:=TStream.Create;
with TFPHTTPClient.Create(nil) do
try
AddHeader('User-Agent','Mozilla/5.0 (compatible; TestApp)');
IOTimeout:=3000;
try
HTTPMethod('GET','https://consumer.oofd.kz/api/tickets/find-by-url?i=3759879297&f=600300097026&s=5032.0&t=20200304T092700',AStream,[302]);
except on E:Exception do
Result:=e.message;
end;
for counter:=0 to ResponseHeaders.Count-1 do
if Pos('Location',ResponseHeaders[counter]) = 0 then Continue else begin
APos:=Pos('/ticket',ResponseHeaders[counter]);
AUID:=Copy(ResponseHeaders[counter],APos,Length(ResponseHeaders[counter])-APos+1);
Break;
end;
//AUID should be something like this '/ticket/ce658ee5-4c10-4c33-b9e9-994ec6226099'
if Pos('/ticket',AUID) > 0 then Result:=Get(Format('%s%s',['https://consumer.oofd.kz/api/tickets',AUID]));
finally
FreeAndNil(AStream);
Free;
end;
end;
...
begin
ShowMessage(GetReceipt);
end.
While looking for solution I've tried jHTTPClient, but it's seems not suitable for my case, because the requested page redirecting to another which is contain data. And I don't know how to handle it.