【问题标题】:Delphi idhttp long URL parameter is splittet automaticallyDelphi idhttp长URL参数自动拆分
【发布时间】:2014-12-26 07:35:26
【问题描述】:

我正在使用 indys idhttp 提交 URL(帖子)

Procedure submit_post(url_string,EncodedStr:string;amemo:TMemo);
var
  aStream: TMemoryStream;
  Params: TStringStream;
begin
  aStream := TMemoryStream.create;
  Params := TStringStream.create('');

  try
    with Fmain.IdHTTP1 do
    begin
      Params.WriteString(EncodedStr);
      Request.ContentType := 'application/x-www-form-urlencoded';
      Request.Charset := 'utf-8';
      try
        Response.KeepAlive := False;
        Post(url_string, params, aStream);
      except
        on E: Exception do
        begin
          Screen.Cursor := crDefault;
          exit;
        end;
      end;
    end;
    aStream.WriteBuffer(#0' ', 1);
    aStream.Position := 0;
    amemo.Lines.LoadFromStream(aStream);
    Screen.Cursor := crDefault;
  finally
    aStream.Free;
    Params.Free;
  end;
end;

它对我来说就像一个魅力。我正在尝试提交一个包含 300 个字符的参数的 URL(帖子),但会通过每 90 个字符添加一个“&”来自动拆分。所以服务器只接收 90 个字符而不是 300 个。

如果没有这种自动分隔,我如何提交一个包含 300 个字符参数的 URL?

【问题讨论】:

  • 请添加您的 url_string 和 EncodedStr 内容,以及到达服务器的确切数据。

标签: delphi post indy idhttp


【解决方案1】:
function SubmitPost(Params:String): string;
const
  URL= 'http://xxxx.com/register.php?';
var
  lHTTP: TIdHTTP;
  Source,
  ResponseContent: TStringStream;
  I:Integer;
begin
  lHTTP := TIdHTTP.Create(nil);
  lHTTP.Request.ContentType := 'text/xml';
  lHTTP.Request.Accept := '*/*';
  lHTTP.Request.Connection := 'Keep-Alive';
  lHTTP.Request.Method := 'POST';
  lHTTP.Request.UserAgent := 'OS Test User Agent';
  Source := TStringStream.Create(nil);
  ResponseContent:= TStringStream.Create;
  try
    try
      lHTTP.Post(URL+Params, Source, ResponseContent);
      Result := ResponseContent.DataString;
    except
      //your exception here
    end;
  finally
    lHTTP.Free;
    Source.Free;
    ResponseContent.Free;
  end;
end;

用法

mmo1.Text := SubmitPost('Username=xxxx&Password=xxxx');

【讨论】:

    【解决方案2】:

    我发现了错误。我的 Post 函数运行良好,但 URL 是由来自备忘录行的参数构建的。使用“WantReturns = FALSE”,我可以构建一个具有最大备忘录行长度的 URL。我猜每行 1024 个字符对我来说没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 2016-04-06
      • 1970-01-01
      相关资源
      最近更新 更多