Delphi time-out setting when using post data

Source: Internet
Author: User

Because the project needs to make HTTP POST submission data, start with the Indy Idhttp component, but when the test found that when the network interruption (such as unplug cable), idhttp timeout setting no effect, wait 20 seconds to prompt timeout (refer to the practice of the Internet, Indy9 upgrade to Indy10, and set the Connettimeout,readtimeout property of the Idhttp, no effect).

Later found that with the ICS component THTTPCLI can be a good control of the commit timeout, to achieve my purpose.

ICS Version: Overbyteicsv7gold

Download: Http://www.overbyte.be/arch/OverbyteIcsV7Gold.zip

Delphi7 Installing ICS

1, the download is completed after extracting to the English directory, it is recommended to extract to the Delphi7 installation directory, such as: C:\Program Files\borland\overbyteicsv7gold

2, Tools--environment options--library, add Overbyteicsv7gold->delphi->vc32 directory in the library path.

3, open the Overbyteicsv7gold->delphi->vc32->overbyteicsd7design.dpk file from File->open, Compile--install.

Unit unit1;interfaceuses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Overbyteics    Wndcontrol, Overbyteicshttpprot, Stdctrls;type TForm1 = Class (Tform) httpcli1:thttpcli;    Button1:tbutton;    Memo1:tmemo;    Edit1:tedit;    Procedure Button1Click (Sender:tobject); Procedure Httpcli1requestdone (Sender:tobject;      Rqtype:thttprequest;  Errcode:word); Private {Private declarations} public {public declarations} End;var form1:tform1;implementation{$R *.dfm}pro  Cedure Tform1.button1click (sender:tobject); var data:string;  retstr:string;  Datalen:int64;           Failmsg:string;begin Data: = ' {' + ' "Machinecode": "123", ' + ' "Orgcode": "123", ' + ' "data": {' + ' "Cardno": "1234       5678 ", ' + '" Cardtype ":" 2 "' + '} ' +    ‘}‘;  Httpcli1.sendstream: = tmemorystream.create;  Httpcli1.rcvdstream: = tmemorystream.create;    Try HttpCli1.SendStream.Write (data[1], Length (Data));    HttpCli1.SendStream.Seek (0, 0);    Httpcli1.url: = Trim (Edit1.text);    Httpcli1.timeout: = 2;//v7.04 sync only!      Try httpcli1.contenttypepost: = ' application/json;charset=utf-8 ';      Httpcli1.post;      Datalen: = HttpCli1.RcvdStream.Size;      SetLength (Retstr,datedelta);      HttpCli1.RcvdStream.Position: = 0;      HttpCli1.RcvdStream.Read (PChar (RETSTR) ^,datalen);      Memo1.text: = Retstr;    ShowMessage (RETSTR);      Except on E:exception do begin ShowMessage (e.message);      End  End    Finally HttpCli1.RcvdStream.Free;    Httpcli1.rcvdstream: = nil;    HttpCli1.SendStream.Free;  Httpcli1.sendstream: = nil; End;end;procedure Tform1.httpcli1requestdone (sender:tobject;  Rqtype:thttprequest; Errcode:word) var data:string;begin//httpcli1.sendstream.free;//Httpcli1.sendstrEAM: = nil;////showmessage (inttostr (Errcode))//if Errcode <> 0 then//with exception//begin//HTTPCLI1.RCVD stream.free;//Httpcli1.rcvdstream: = nil;//exit;//end;//if Httpcli1.statuscode <> then/ /return error//begin//httpcli1.rcvdstream.free;//Httpcli1.rcvdstream: = nil;//exit;//end;//Htt PCli1.RcvdStream.Seek (0, 0);//SetLength (Data, HttpCli1.RcvdStream.Size);//HttpCli1.RcvdStream.Read (data[1], lengt H (Data)); End;end.

 

installation package and demo Download:

http://download.csdn.net/detail/tc310/9384426

Delphi time-out setting when using post data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.