| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
- IdHTTP, StdCtrls;
- type
- TForm1 = class(TForm)
- btnPost: TButton;
- IDHTTP: TIdHTTP;
- mmInfo: TMemo;
- mmResult: TMemo;
- procedure btnPostClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- function UploadData: Boolean;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- function TForm1.UploadData: Boolean;
- var
- sURL, sR: string;
- bDone: Boolean;
- vPostList: TStrings;
- I: Integer;
- begin
- Result := False;
- mmResult.Text := '';
- sURL := 'http://39.108.111.147:7777/counter/update';
- vPostList := TStringList.Create;
- try
- try
- vPostList.Assign(mmInfo.Lines);
- for I := 0 to vPostList.Count - 1 do
- vPostList[I] := AnsiToUtf8(vPostList[I]);
- sR := IdHTTP.Post(sURL, vPostList);
- bDone := True;
- except
- bDone := False;
- end;
- sR := Utf8ToAnsi(sR);
- // '200 OK'±íʾÇëÇó³É¹¦
- mmResult.Text := sR + #13#10 + IDHTTP.ResponseText;
- finally
- vPostList.Free;
- end;
- end;
- procedure TForm1.btnPostClick(Sender: TObject);
- begin
- UploadData;
- end;
- end.
|