Delphi 7 http request in line

I want to load url directly into a string without data stream, which is the best way, internet open url works, but it seems obscure.

I do not want to use any component for reading short messages

-1
source share
4 answers

Delphi 6 and later ships with Indy, which has a TIdHTTP client component, for example:

 uses ..., IdHTTP; var Reply: String; begin Reply := IdHTTP1.Get('http://test.com/postaccepter?=msg1=3444&msg2=test'); ... end; 

Or:

 uses ..., IdHTTP; var Reply: TStream; begin Reply := TMemoryStream.Create; try IdHTTP1.Get('http://test.com/postaccepter?=msg1=3444&msg2=test', Reply); Reply.Position := 0; ... finally Reply.Free; end; end; 

Depending on your needs.

+6
source

You can use Synapse , a very lightweight library with a simple function call, to get just what you ask for:

 uses classes, httpsend; var Response : TStringlist; begin if HttpGetText(URL,Response) then DoSomethingWithResponse(Response.Text); end; 

I would suggest getting the latest copy of SVN , which is more relevant and contains support for the latest versions of Delphi. There are also simple functions for publishing form data or retrieving binary resources. They are implemented as simple functions and are a great template if you want to do something extra or not be supported directly.

+3
source

You can use our SynCrtSock block, which is even brighter than Synapse.

See http://synopse.info/fossil/finfo?name=SynCrtSock.pas

This is a standalone block (only one dependency with a WinSock block), and it runs from Delphi 6 to Delphi XE.

You have two functions available to receive your data in one line of code:

 /// retrieve the content of a web page, using the HTTP/1.1 protocol and GET method function HttpGet(const server, port: AnsiString; const url: TSockData): TSockData; /// send some data to a remote web server, using the HTTP/1.1 protocol and POST method function HttpPost(const server, port: AnsiString; const url, Data, DataType: TSockData): boolean; 

Or you can use text file-based commands (such as readln or writeln) to retrieve or save data.

TSockData is just a RawByteString shell (in Delphi 2009/2010 / XE) or AnsiString (before Delphi 2007).

If you also need to write a server, you allocate classes at hand, which leads to fast processing and low resource consumption (it uses a thread pool and is implemented through input / output completion ports).

+1
source

If I already use XML in the application (and MSXML2_TLB), I usually use IXmlHttpRequest to perform HTTP operations. If you open and send a request, you can use the response data as an XML DOM using ResponseXML, as text using a ResponseText, or as a data stream using a ResponseStream, see here an example of using this in Delphi: http://yoy.be/item .asp? i142

0
source

All Articles