What's the simplest way to call Http GET url u

2019-01-05 00:09发布

There's a web services I want to call in my application, I can use it with importing the WSDL or by just use "HTTP GET" with the URL and parameters, so I prefer the later because it's simple thing.

I know I can use indy idhttp.get, to do the job, but this is very simple thing and I don't want to add complex indy code to my application.

UPDATE: sorry if I was not clear, I meant by "not to add complex indy code", that I don't want add indy components for just this simple task, and prefer more lighter way for that.

8条回答
三岁会撩人
2楼-- · 2019-01-05 00:29

If your application is Windows-only, I would suggest using WinSock. It's simple enough, allows to execute any HTTP request, can work both synchronously and asynchronously (using non-blocking WSASend/WSARecv with callbacks or good old send/recv in a dedicated thread).

查看更多
来,给爷笑一个
3楼-- · 2019-01-05 00:34

Calling a RESTful web service using Indy is pretty straight forward.

Add IdHTTP to your uses clause. Remember that IdHTTP needs the "HTTP://" prefix on your URLs.

function GetURLAsString(const aURL: string): string;
var
  lHTTP: TIdHTTP;
begin
  lHTTP := TIdHTTP.Create;
  try
    Result := lHTTP.Get(aURL);
  finally
    lHTTP.Free;
  end;
end;
查看更多
登录 后发表回答