stevewong Posted October 6, 2020 Posted October 6, 2020 Hi, Can anyone tell me how to use TNetHTTPClient in unigui app. I was trying to make some RESTFUL call in my unigui app. However, whenever I try to do : http := TNetHTTPClient.create; in my unigui app, I got an exception : Net HTTPClientException : Error obtaining session handle I then try to put the TNetHTTPClient component into mainmodule so that I do not need to create it. However, the unigui app give me a blank screen when I try to access the unigui page (e.g. https//x.com/app.dll). I was using Delphi 10.3.2, web server is windows server IIS 7, unigui version 1.90.0.1511 Or can anyone tell me to issue Restful call within the unigui app, thanks ! Quote
stevewong Posted October 7, 2020 Author Posted October 7, 2020 I tried with Indy ThttpClient. the code then stopped at the statement http.post(.....), with an invalid address exception. The same set of http.post(...) code was working fine under VCL. so I do suspected that I can not use ThttpClient or TNetHTTPclient in the hyperserver + IIS enviroment. Quote
alfr Posted October 7, 2020 Posted October 7, 2020 I believe Kenneth is not referring to the indy client. Instead the delphi native one - that is built on the windows version (works on modern versions of windows). uses System.net.Httpclient; var Http: THttpclient; Shorted working example from unigui Http:=THttpclient.Create; try Res:=Http.Get('https://integration.com/api/v2/orders/' + OrderID.ToString + '?token=' + TheirToken); if Res = nil then begin ShowMessage('Error in retrieving OrderID ' + OrderID.ToString + ' from X! Respons is empty!'); exit; end; if Res.StatusCode = 200 then begin TheOrder:=TOrderClass.FromJsonString(Res.contentasString(Tencoding.UTF8)); end else begin ShowMessage('Did''t get Result 200 in reply from X! Result = ' + Res.StatusCode.ToString + ' ' + Res.StatusText); end; finally Http.Free; end; Some more info from Embarcadero http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Net.HttpClient.THTTPClient But perhaps your problems indicate some other problems in your code? Are you perhaps creating the client to early? Would suggest that you create it as my sample - in the procedure where you use it. Quote
ReaderF Posted October 8, 2020 Posted October 8, 2020 On 10/7/2020 at 1:18 PM, alfr said: I believe Kenneth is not referring to the indy client. Instead the delphi native one - that is built on the windows version (works on modern versions of windows). uses System.net.Httpclient; var Http: THttpclient; Shorted working example from unigui Http:=THttpclient.Create; try Res:=Http.Get('https://integration.com/api/v2/orders/' + OrderID.ToString + '?token=' + TheirToken); if Res = nil then begin ShowMessage('Error in retrieving OrderID ' + OrderID.ToString + ' from X! Respons is empty!'); exit; end; if Res.StatusCode = 200 then begin TheOrder:=TOrderClass.FromJsonString(Res.contentasString(Tencoding.UTF8)); end else begin ShowMessage('Did''t get Result 200 in reply from X! Result = ' + Res.StatusCode.ToString + ' ' + Res.StatusText); end; finally Http.Free; end; Some more info from Embarcadero http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Net.HttpClient.THTTPClient But perhaps your problems indicate some other problems in your code? Are you perhaps creating the client to early? Would suggest that you create it as my sample - in the procedure where you use it. Try use restrequest4delphi https://blogs-embarcadero-com.cdn.ampproject.org/c/s/blogs.embarcadero.com/powerful-open-source-restrequest4delphi-makes-rest-easy-in-delphi/amp/ 1 Quote
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.