#pragma once
#include "commanage.h"
#include "windowsAPI.h"
#include "xmlReader.h"
#include <nlite_cookie\cookie.h>
#import "winhttp.dll" named_guids


#include "namespace_start.h"
class CWinHttpClient {
private:
	CComManage m_com;
	WinHttp::IWinHttpRequestPtr m_ptr;
public:

	///
	///URLオープン
	///
	CHResult Open(const NString &method,const NString &url,const _variant_t &async = vtMissing); 


	///
	///レスポンスからIStreamを取得
	///
	CHResult get_Response(IStream **ppStream);

	///
	///ヘッダセット
	///
	CHResult SetRequestHeader(const NString &headerName,const NString &headerBody);

	CHResult SetRequestHeader(const cookie::CCookie &val);

	///
	///データ送信
	///
	CHResult Send(const _variant_t &value = vtMissing);

	CWinHttpClient();



	//
	//テンプレート関数
	//
	template<typename F>
	CHResult get_ResponseXml(F func){

		CComPtr<IStream> pStream;
		CHResult result = this->get_Response(&pStream);

		if(result.IsSucceded()){

			CXmlReader xmlReader;
		
			xmlReader.Create();

			xmlReader.SetInput(pStream);


			result = func(xmlReader);
				
			CHECK_HRESULT(result);

		}


		return result;
	}



};
#include "namespace_end.h"