반응형
var
idhttp : TIdHttp;
aData : TStringList;
ms : TMemoryStream;
mime : TIdMultiPartFormDataStream;
i : Integer;
aURL : String;
ResultStr : String;
begin
ResultStr := '';
aURL := 'http://id.naver.com/nidlogin.login';
idhttp := TIdHttp.Create;
aData := TStringList.Create;
ms := TMemoryStream.Create;
mime := TIdMultiPartFormDataStream.Create;
try
// idhttp init
idHttp.Host := URL;
idHttp.Request.Referer := URL;
idHttp.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)';
idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
idHttp.HandleRedirects := true;
// data
aData.Add('id=아이디');
aData.Add('pw=패스워드');
// data input
idHttp.Request.ContentType := mime.RequestContentType;
for i := 0 to aData.Count - 1 do
mime.AddFormField(aData.Names[i], aData.Values[aData.Names[i]]);
mime.Position := 0;
// post data
idHttp.Post(aURL, mime, ms);
// data response
if ms.Size > 0 then
begin
SetLength(ResultStr, ms.Size);
Move(PChar(ms.Memory)^, ResultStr[1], ms.Size);
end;
finally
idhttp.Free;
aData.Free;
ms.Free;
mime.Free;
end;
end;
idhttp : TIdHttp;
aData : TStringList;
ms : TMemoryStream;
mime : TIdMultiPartFormDataStream;
i : Integer;
aURL : String;
ResultStr : String;
begin
ResultStr := '';
aURL := 'http://id.naver.com/nidlogin.login';
idhttp := TIdHttp.Create;
aData := TStringList.Create;
ms := TMemoryStream.Create;
mime := TIdMultiPartFormDataStream.Create;
try
// idhttp init
idHttp.Host := URL;
idHttp.Request.Referer := URL;
idHttp.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)';
idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
idHttp.HandleRedirects := true;
// data
aData.Add('id=아이디');
aData.Add('pw=패스워드');
// data input
idHttp.Request.ContentType := mime.RequestContentType;
for i := 0 to aData.Count - 1 do
mime.AddFormField(aData.Names[i], aData.Values[aData.Names[i]]);
mime.Position := 0;
// post data
idHttp.Post(aURL, mime, ms);
// data response
if ms.Size > 0 then
begin
SetLength(ResultStr, ms.Size);
Move(PChar(ms.Memory)^, ResultStr[1], ms.Size);
end;
finally
idhttp.Free;
aData.Free;
ms.Free;
mime.Free;
end;
end;
반응형