본문 바로가기
코드

WebDAV (FireMonkey)

by umaking 2014. 6. 27.
안드로이드에서 동작 확인함.

#include 
#include 





// ---------------------------------------------------------------------------
void __fastcall TForm1::WebDAVClient(String host, String port, String path) {
	TStream* XMLQuery = new TMemoryStream;
	TStream* AResponseContent = new TMemoryStream;

	String xmlStr = "\n\r" \
 "\n\r" \
 "   \n\r" \
 "\n\r";

	WriteStringToStream(XMLQuery, xmlStr, TIdTextEncoding_UTF8);

	IdWebDAV1->Request->ContentType = "text/xml";
	IdWebDAV1->Request->CharSet = "utf-8";
	IdWebDAV1->URL->Host = host;
	IdWebDAV1->URL->Port = port;
	IdWebDAV1->Request->BasicAuthentication = false;

	// 최초 nonce, realm, qop 등을 받음.
	try {
		IdWebDAV1->Get(path, AResponseContent);
	}
	catch (...) {
	}

	//
	TIdHeaderList* headerList = IdWebDAV1->Response->WWWAuthenticate;

	// 두번째 인증 함.
	TIdDigestAuthentication* auth = new TIdDigestAuthentication;
	auth->Username = "아이디";
	auth->Password = "암호";
	auth->AuthParams = headerList;
	auth->Next();

	IdWebDAV1->Request->Authentication = auth;

	try {
		IdWebDAV1->DAVPropFind(path, XMLQuery, AResponseContent, 1);
	}
	catch (...) {
	}

	Memo1->Lines->Add(IdWebDAV1->ResponseCode);

	if (IdWebDAV1->ResponseCode == 207) {
		TStrings *str2 = getContents(AResponseContent);
		Memo1->Lines->Add(str2->Text);
	}

	delete XMLQuery;
	delete AResponseContent;
}

// ---------------------------------------------------------------------------
TStrings* __fastcall TForm1::getContents(TStream *stream) {
	TStrings *str = new TStringList();
	long size = 0;
	char *buf = NULL;

	DebugOutput("Position : " + IntToStr(stream->Position));

	stream->Position = 0;
	str->BeginUpdate();
	try {
		size = stream->Size;

		buf = new char[size + 1];

		stream->ReadBuffer(buf, size);
		buf[size] = 0;

		str->Text = buf;

		delete[]buf;
		size = 0;
	}
	__finally {
		str->EndUpdate();
		stream->Position = 0;
	}

	return str;
}


'코드' 카테고리의 다른 글

Datagrip에서 dbms_output 출력하기  (1) 2021.04.03
Swift프로젝트에 AFNetworking 의존성 추가하기.  (0) 2015.09.20
Cam  (0) 2010.08.10
unzip  (2) 2010.08.03
FindWindow  (0) 2010.07.13