#1 2017-03-02 07:41:14

Ericshen
Member
Registered: 2017-02-25
Posts: 10

I want use mormt to instead of NetHttpClient

Hi ab,


I would like use mormot to  callback another web site for his web API?   how to use?

Thank you

like this:

aURL : [url]https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s[/url]

function HTTP_Request(aURL, UTF8:string; RequestMode: string): AnsiString;
var
   MyHttp : TNetHTTPClient;
   aUTF8: TStringStream;
begin
   Result := '';
   MyHttp := TNetHTTPClient.Create(nil);
   aUTF8 := TStringStream.create;
   try
      with MyHttp do
      begin
          aUTF8.Clear;
          ConnectionTimeout := 2000;
          ResponseTimeout  := 10000;
          AcceptCharSet  := UTF8;
          AcceptEncoding := '65001';
          AcceptLanguage := 'zh-CN';
          ContentType := 'text/Html';
          try
            if LowerCase(RequestMode) = 'get' then
               Get(aURL,aUTF8)
            else
            if LowerCase(RequestMode) = 'set' then
              exit;// Post(aURL);
            Result := aUTF8.DataString;
          except
            on E: Exception do
              showmessage(e.Message);
          end;
      end;
   finally
     FreeAndNil(MyHttp);
     FreeAndNil(aUTF8);
   end;
end;

Offline

#2 2017-03-02 15:04:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: I want use mormt to instead of NetHttpClient

On which compiler?
On which OS / platform?

Offline

#3 2017-03-02 16:17:04

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: I want use mormt to instead of NetHttpClient

I just use HttpGet()

Offline

#4 2017-03-02 16:22:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: I want use mormt to instead of NetHttpClient

From SynCrtSock.pas unit.

Offline

#5 2017-03-03 00:43:03

Ericshen
Member
Registered: 2017-02-25
Posts: 10

Re: I want use mormt to instead of NetHttpClient

Thanks ,ab

my code complier on delphi 10.1 and win 10 64

Offline

#6 2017-03-03 00:51:58

Ericshen
Member
Registered: 2017-02-25
Posts: 10

Re: I want use mormt to instead of NetHttpClient

Thank esmondb and thank ab again!  I Got  it ,used ok!

Offline

Board footer

Powered by FluxBB