MOGSY Posted September 7, 2020 Share Posted September 7, 2020 Hi How is possible in UniGui to send a https request and collect the response i.e. sending a request to Google and get the response. https://maps.googleapis.com/maps/api/distancematrix/json?mode=driving&units=imperial&origins=52.779323,-1.211226&destinations=52.643617,-1.126523&key=AIzaSyC41PXsKVx3DmU0sbYy1coK8HUz9WhXFgM Google response would like { "destination_addresses" : [ "257 Belgrave Gate, Leicester LE1 3HU, UK" ], "origin_addresses" : [ "Cloudway Court, Belton Rd, Loughborough LE11 1LW, UK" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "12.4 mi", "value" : 20029 }, "duration" : { "text" : "27 mins", "value" : 1615 }, "status" : "OK" } ] } ], "status" : "OK" } Thank you. Quote Link to comment Share on other sites More sharing options...
RobertoLopes Posted September 9, 2020 Share Posted September 9, 2020 I do that with several google apis BUT, not thru Unigui. Using C++ builder/Delphi TNetHTTP component. It works. Quote Link to comment Share on other sites More sharing options...
MOGSY Posted September 9, 2020 Author Share Posted September 9, 2020 Hi Roberto Would mind sharing example code please. regards Quote Link to comment Share on other sites More sharing options...
Kenneth Posted September 9, 2020 Share Posted September 9, 2020 var h:THTTPClient; R:IHTTPResponse; s:TStringStream; begin h:=THTTPClient.Create; s:=TStringStream.Create; try R:=h.Get('http://google.com/yourQuery', s); if R.StatusCode = 200 then s.DataString; //<--- your JSON request finally FreeAndNil(h); FreeAndNil(s); end; end; 1 Quote Link to comment Share on other sites More sharing options...
MOGSY Posted September 11, 2020 Author Share Posted September 11, 2020 Thank you Quote Link to comment Share on other sites More sharing options...
Ron Posted September 17, 2020 Share Posted September 17, 2020 uses System.Net.HttpClientComponent, function getHTML(URL:string):string; var aResponse: TStringStream; http: TNetHTTPClient; begin result:=''; try http:=TNetHTTPClient.Create; aResponse := TStringStream.Create; try http.Get(url, aResponse); result:= aResponse.DataString; finally aResponse.Free; http.free; end; except on E:Exception do showMessage('Get htmlfile error: '+ E.Message); end; end; Using TNetHTTPClient makes it a lot easier to connect to different webservers that have strict requirements when it comes to SSL setup, than when using Indy. Quote Link to comment Share on other sites More sharing options...
MOGSY Posted September 17, 2020 Author Share Posted September 17, 2020 thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.