Delphi TIdHTTP POST与GET相比非常慢 [英] Delphi TIdHTTP POST is very slow vs GET

查看:214
本文介绍了Delphi TIdHTTP POST与GET相比非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi 2009

Delphi 2009

我最近从多个GET请求切换到了一个POST,我认为这样做会更高效,但事实却要慢得多。它从1-2秒变为了8-10秒,我不知道为什么。

I recently switched from multiple GET requests to a single POST which I thought would be more efficient but it has turned out to be much slower. It went from 1-2 seconds to 8-10 seconds and I can't figure out why.

示例

unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP;

type
  TForm4 = class(TForm)
    d: TIdHTTP;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.Button1Click(Sender: TObject);
var m: tmemorystream;
    data: tstringlist;
    i: integer;
begin
  memo1.Clear;

  m:=tmemorystream.Create;
  data:=tstringlist.Create;
  data.Add(format('test1');
  data.Add(format('test2');

  d.Post('http://www.someurl.com/test.php', data, m);
  m.Position:=0;
  data.LoadFromStream(m);
  memo1.Lines.Add('Received:');

  for i := 0 to data.count - 1 do
    memo1.Lines.Add(data[i]);

  m.Free;
  data.Free;
end;

end.

并在服务器上

<?php
echo "1\n";
?>


推荐答案

我使用不同的网址进行了简单的测试:

I did a simple test using different urls:

d.Post('http://whatismyip.org', data, m); // Using DNS name

d.Post('http://54.242.203.46', data, m); // Using IP

帖子花费了大约1秒钟的时间,因此我认为您的问题可能与Indy无关。我的建议:

The Post took ~1 sec, so I think your problem may not be connected with Indy. My suggestions:


  • 检查PC的DNS解析。请尝试使用IP地址查看如果存在差异;

  • 尝试使用外部工具(curl,vbscript等)向同一站点发出POST请求,并测量时间;

  • 使用网络监视工具(Wireshark,MS网络监视器等)来查看服务器响应您的POST请求所花费的时间,或者客户端在解析地址和实际的Post请求之间所花费的时间。

这些步骤可以缩小问题所在。

These steps can narrow where the problem is.

如果上述所有方法均无效,请尝试将Indy升级到最新版本。

If none of these help - try upgrading Indy to the latest version.

这篇关于Delphi TIdHTTP POST与GET相比非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆