//Àúó·³ ½Ã°£³¶ºñÇϽô ºÐµéÀÌ ¾øµµ·Ï ½ÇÁ¦Àû¿ë¼Ò½º¸¦ ±×´ë·Î ¿Ã¸³´Ï´Ù. ÇÊ¿äÇÑ ºÐµé¿¡°Ô µµ¿òÀÌ µÇ¾úÀ¸¸é ÇÕ´Ï´Ù.
unit upost;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, xmldom, XMLIntf, msxmldom, XMLDoc,HTTPApp;
type TForm8 = class(TForm) Button1: TButton; Edit1: TEdit; Memo1: TMemo; GroupBox1: TGroupBox; RadioButton1: TRadioButton; RadioButton2: TRadioButton; IdHTTP1: TIdHTTP; XMLDocument1: TXMLDocument; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form8: TForm8;
implementation
{$R *.dfm}
procedure TForm8.Button1Click(Sender: TObject); var
Url , code ,searchword , searchoption : AnsiString ;
Data : TStringStream; DResult : TStringStream; Indy : TIdHTTP;
OuterRoot,EntryNode:IXmlNode; i,j:Integer; begin
memo1.clear;
Data := TStringStream.Create(''); DResult := TStringStream.Create(''); Indy := TIdHttp.Create(nil);
try // Indy¸¦ ÀÌ¿ëÇؼ get //Indy.Request.ContentType := 'application/x-www-form-urlencoded'; // post¹æ½Ä Indy.Request.ContentType := 'application/json';
//data.go.kr¿¡ ȸ¿ø°¡ÀÔÈÄ ·Î±×ÀÎÇÏ¿© ½Åû¹Þ¾Æ ºÎ¿©¹ÞÀº [ÀÎÁõÅ°]¸¦ codeº¯¼ö¿¡ ÀÔ·ÂÇϼ¼¿ä. code := 'GPpOp3414p31PrYjYMKTJRbo1bIgVHN1%2F7d2akXu3sZ0qpR1PObVmrxsmwfea7qBSY5FarGxtKIcjZTsVcVNFlSs%2idBg2w%3D%3D'; //À̺κРÀÎÄÚµùÇÏ¸é ¾ÈµË´Ï´Ù. searchword := HttpEncode(UTF8Encode('¼¼Á¾·Î 17')); //µµ·Î¸í °Ë»ö¾î if (RadioButton1.Checked=true ) then begin searchoption :='&searchSe=road'; end else if (RadioButton2.Checked=true ) then begin searchoption :='&searchSe=dong'; end; //Á¤»óÈ£Ãâ url ->> http://openapi.epost.go.kr/postal/retrieveNewAdressAreaCdService/retrieveNewAdressAreaCdService/getNewAddressListAreaCd?ServiceKey=ÀÎÁõÅ°&searchSe=road&srchwrd=¼¼Á¾·Î 17 Url:= 'http://openapi.epost.go.kr/postal/retrieveNewAdressAreaCdService/retrieveNewAdressAreaCdService/getNewAddressListAreaCd'; Indy.get(Url+UTF8Encode('?ServiceKey=')+code+UTF8Encode(searchoption)+UTF8Encode('&srchwrd=')+searchword,DResult); // Indy.get(Url+'?ServiceKey='+code+searchoption+'&srchwrd='+searchword,DResult); XMLDocument1.LoadFromStream(DResult); XMLDocument1.Active:=True;
// stream µÈ ³»¿ë ÆÄÀÏ »ý¼ºÇÕ´Ï´Ù. //XMLDocument1.SaveToFile('C:\Documents and Settings\tigger\¹ÙÅÁ ȸé\1.xml');
OuterRoot := xmldocument1.DocumentElement; for i := 0 to OuterRoot.ChildNodes.Count -1 do begin if OuterRoot.ChildNodes[i].NodeName='newAddressListAreaCd' then begin Memo1.Lines.Add(StringOfChar('-',20)); Memo1.Lines.Add(OuterRoot.ChildNodes[i].NodeName +':'); EntryNode := OuterRoot.ChildNodes[i]; for j := 0 to EntryNode.ChildNodes.Count -1 do begin Memo1.Lines.Add( EntryNode.ChildNodes[j].NodeName + '-' + EntryNode.ChildNodes[j].Text); end; end; end;
finally // ¸Þ¸ð¸®¿¡¼ ÇØÁ¦ Data.Free; DResult.Free; Indy.Free;
end; end;
end.
|