Unit1.pas 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. unit Unit1;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  6. IdHTTP, StdCtrls;
  7. type
  8. TForm1 = class(TForm)
  9. btnPost: TButton;
  10. IDHTTP: TIdHTTP;
  11. mmInfo: TMemo;
  12. mmResult: TMemo;
  13. procedure btnPostClick(Sender: TObject);
  14. private
  15. { Private declarations }
  16. public
  17. { Public declarations }
  18. function UploadData: Boolean;
  19. end;
  20. var
  21. Form1: TForm1;
  22. implementation
  23. {$R *.dfm}
  24. function TForm1.UploadData: Boolean;
  25. var
  26. sURL, sR: string;
  27. bDone: Boolean;
  28. vPostList: TStrings;
  29. I: Integer;
  30. begin
  31. Result := False;
  32. mmResult.Text := '';
  33. sURL := 'http://39.108.111.147:7777/counter/update';
  34. vPostList := TStringList.Create;
  35. try
  36. try
  37. vPostList.Assign(mmInfo.Lines);
  38. for I := 0 to vPostList.Count - 1 do
  39. vPostList[I] := AnsiToUtf8(vPostList[I]);
  40. sR := IdHTTP.Post(sURL, vPostList);
  41. bDone := True;
  42. except
  43. bDone := False;
  44. end;
  45. sR := Utf8ToAnsi(sR);
  46. // '200 OK'±íʾÇëÇó³É¹¦
  47. mmResult.Text := sR + #13#10 + IDHTTP.ResponseText;
  48. finally
  49. vPostList.Free;
  50. end;
  51. end;
  52. procedure TForm1.btnPostClick(Sender: TObject);
  53. begin
  54. UploadData;
  55. end;
  56. end.