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 文字ごとに「&」を追加することで自動的に分割されます。そのため、サーバーは 300 文字ではなく 90 文字しか受け取りません。

この自動分離なしで 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 に答える