1

我正在使用 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?

4

2 回答 2

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');
于 2014-11-04T19:18:57.613 回答
0

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

于 2014-11-05T15:43:11.220 回答