나도초짜 님이 쓰신 글 :
: 안녕 하세요..
: 초보적인 질문인지는 모르겠는데 모르니까 무지 답답하네요..
:
: WebBrowser 에서 Navigate로 웹페이지 하나를 지정해서 접속을 했는데..
:
: 거기에보면 다운로드 버튼이 하나 있는데 이버튼을 눌러서 해당 파일을
: 자동으로 받는 프로그램을 만들고 싶어요...
:
: 그런데 Text 소스를 보니 이 버튼을 누르면 아래 행을 실행하게 되어 있더라구요..
: function excel_save() {
: document.all.excel_iframe.src="ma_st_item_con_lst_viw_excel.jsp?indx_cd=&indx_ind_cd=&cur_pr=&cur_pr_type=&cur_pr1=&cur_pr2=&tr_vl=&tr_vl_type=&tr_vl1=&tr_vl2=&isu_stat=1&isu_stat_type=1&woo=&woo_type=&too_type=&too_type1=&too_type2=&too_type3=";
: }
:
: 이걸 어떻게 전달을 하여 실행을 할수 있을지..
:
: PostData를 지정하는것같은데.. PostData 함수까지는 구현 하였는데..
: PostData로 도데체 뭘 넘겨 줘야할지를 모르겠네요..
:
: 고수님들의 답변좀 부탁 드립니다.
:
: 그럼 꾸벅..
간단한 예를 들면 아래와 같이 할 수 있습니다.
Params의 각 항목의 값을 분리해서 지정해야 할텐데요 그것은 별로 어려운 작업이 아닙니다.
(분리해서 지정한 다음 다시 아래의 형식으로 합쳐야 겠지요)
분리해서 지정하려면 각 항목의 의미를 알아야 가능한데요.
그 것은 해당 URL의 결과 HTML 소스에서 해당 Form 영역을 살펴보면 답이 다 나와 있습니다.
예를 들어, '종합주가지수'라고 초기에 표시되는 항목의 이름은 indx_ind_cd이고
그것에 지정할 수 있는 값은 01 에서 40 ('종합주가지수'~'배당지수')까지인 것을 알 수 있습니다.
String Host("www.kse.or.kr");
String CGI("/webkor/market/st/item/con/ma_st_item_con_lst_viw_excel.jsp");
String Params("indx_cd=1&indx_ind_cd=01&cur_pr=&cur_pr_type=&cur_pr1=&cur_pr2=&tr_vl=&tr_vl_type=&tr_vl1=&tr_vl2=&isu_stat=&isu_stat_type=&woo=&woo_type=&too_type=&too_type1=&too_type2=&too_type3=");
void __fastcall TForm1::btnGetClick(TObject *Sender)
{
Screen->Cursor = crHourGlass;
TMemoryStream *pMStream = new TMemoryStream;
IdHTTP1->Get("
Http:://"+Host+CGI+"?"+Params,pMStream);
IdHTTP1->Response->ExtraHeaders->CaseSensitive = false;
//Content-Disposition: attachment; filename=20040917165039_file.xls
String content_disp = IdHTTP1->Response->ExtraHeaders->Values["Content-Disposition"];
String file_name;
int idx = content_disp.LowerCase().Pos("filename=");
if(idx>=1)
{
file_name = content_disp.SubString(idx+9,content_disp.Length());
if(file_name.IsEmpty()==false)
{
TFileStream *pFStream = new TFileStream(file_name,fmCreate|fmShareDenyWrite);
pFStream->CopyFrom(pMStream,0);
delete pFStream;
}
}
delete pMStream;
Screen->Cursor = crDefault;
}