[delphi] indy idhttp post 방법
function Post(AURL: string; ASource: TIdStrings): string; overload;
function Post(AURL: string; ASource: TStream): string; overload;
function Post(AURL: string; ASource: TIdMultiPartFormDataStream): string; overload;
procedure Post(AURL: string; ASource: TIdMultiPartFormDataStream; AResponseContent: TStream); overload;
procedure Post(AURL: string; ASource: TIdStrings; AResponseContent: TStream); overload;
procedure Post(AURL: string; ASource, AResponseContent: TStream); overload;
이러한 기본 방법은 다음 프로세스 클래스이며 기타 post 재부팅 방법은 모두 중첩에 사용됩니다.
procedure TIdCustomHTTP.Post(AURL: string; ASource, AResponseContent: TStream);
매개변수:
AURL: string // post URL
ASource: TIdMultiPartFormDataStream // TStream , mime ,
ASource: TStream //
AResponseContent: TStream // ASource: TIdStrings // TString ,
Asource는 TidStrings 데이터로 사용되는 MIME는 기본 '응용 프로그램/x-ww-form-urlencoded' 이고 TidMultiForm DataStream은 보내는 내용/파일에 따라 MIME 형식을 설정합니다.
예:
unit Umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, IdMultipartFormData;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
btnOne: TButton;
btnTwo: TButton;
btnThree: TButton;
btnFour: TButton;
btnFive: TButton;
btnSix: TButton;
procedure btnOneClick(Sender: TObject);
procedure btnTwoClick(Sender: TObject);
procedure btnThreeClick(Sender: TObject);
procedure btnFourClick(Sender: TObject);
procedure btnFiveClick(Sender: TObject);
procedure btnSixClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
sPostUrl = 'http://cne.csu.edu.cn/reg/mima-pass.asp?path=';
procedure TForm1.btnOneClick(Sender: TObject);
var
postcmd : TStringList;
begin
postcmd := TStringList.Create; //
postcmd.Add('AutoGet=1');
postcmd.Add('Logintype=0');
postcmd.Add('password=test');
postcmd.Add('username=test');
Memo1.Text := IdHTTP1.Post(sPostUrl, postcmd); // post
end;
procedure TForm1.btnTwoClick(Sender: TObject);
var
postStream : TStringStream;
begin
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; // mime
postStream := TStringStream.Create('AutoGet=1&Logintype=0&password=test&username=test'); //
Memo1.Text := IdHTTP1.Post(sPostUrl, postStream);
end;
procedure TForm1.btnThreeClick(Sender: TObject);
var
postStream : TIdMultiPartFormDataStream;
begin
IdHTTP1.HandleRedirects := true; // ,
IdHTTP1.Request.Referer := 'http://www.qiuziti.com/'; // ,
postStream := TIdMultiPartFormDataStream.Create; // TIdMultiPartFormDataStream
postStream.AddFormField('textfield', 'd:\temp\test.png'); //
postStream.AddFile('uploaded_file', 'd:\temp\test.png', 'image/png'); //
Memo1.Text := Utf8ToAnsi(IdHTTP1.Post('http://www.qiuziti.com/s/upload.ashx', postStream));
end;
procedure TForm1.btnFourClick(Sender: TObject);
var
postStream : TIdMultiPartFormDataStream;
respStream : TStringStream;
begin
IdHTTP1.HandleRedirects := true; // ,
IdHTTP1.Request.Referer := 'http://www.qiuziti.com/'; // ,
postStream := TIdMultiPartFormDataStream.Create; // TIdMultiPartFormDataStream
respStream := TStringStream.Create('');
postStream.AddFormField('textfield', 'd:\temp\test.png'); //
postStream.AddFile('uploaded_file', 'd:\temp\test.png', 'image/png'); //
IdHTTP1.Post('http://www.qiuziti.com/s/upload.ashx', postStream, respStream);
Memo1.Text := Utf8ToAnsi(respStream.DataString);
end;
procedure TForm1.btnFiveClick(Sender: TObject);
var
respStream : TStringStream;
postcmd : TStringList;
begin
postcmd := TStringList.Create;
respStream := TStringStream.Create('');
postcmd.Add('AutoGet=1');
postcmd.Add('Logintype=0');
postcmd.Add('password=test');
postcmd.Add('username=test');
IdHTTP1.Post(sPostUrl, postcmd, respStream);
Memo1.Text := respStream.DataString;
end;
procedure TForm1.btnSixClick(Sender: TObject);
var
postStream, respStream : TStringStream;
begin
postStream := TStringStream.Create('AutoGet=1&Logintype=0&password=test&username=test');
respStream := TStringStream.Create('');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; // mime
IdHTTP1.Post(sPostUrl, postStream, respStream);
Memo1.Text := respStream.DataString;
end;
end.
데모 다운로드:
http://download.csdn.net/detail/none01/5130108
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Delphi 목마 자기 복제법 구현목마가 자기 복사를 실현하는 원리는 프로그램이 실행될 때 먼저 자신이 특정 디렉터리에 있는지 확인하고 그렇지 않으면 계속 실행하며 그렇지 않으면 특정 디렉터리에 복사한 다음에 새로운 프로그램을 실행하고 낡은 프로그램...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.