#ifndef CHTTPCLIENT_H
#define CHTTPCLIENT_H

#include <QString>

#include <curl/curl.h>
#include <vector>

enum FORM_DATA_TYPE
{
    fdt_content,
    fdt_file
};

class CHttpClient
{
public:
    CHttpClient();
    ~CHttpClient();
    void addParam(std::string sKey, std::string sValue);
    void addHeader(std::string sKey, std::string sValue);
    void addFormData(FORM_DATA_TYPE nType, std::string sKey, std::string sValue);
	void addFormDataList(FORM_DATA_TYPE nType, std::string sKey, std::vector<std::string> sValue);
    bool post(std::string uri, std::string &sResponse, int &nResCode);
    bool post(std::string uri, std::string sPostStr, std::string &sResponse, int &nResCode);
    bool postFormData(std::string uri, std::string &sResponse, int &nResCode);
    bool get(std::string uri, std::string &sResponse, int &nResCode);
	bool put(std::string uri, std::string &sResponse, int &nResCode);
    bool download(std::string uri, std::string sFileName, int &nResCode);
    void setTimeOut(int nTimeOut);
private:
	static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm);
    std::string encodeStr(std::string sStr);
    std::string encodeURL(std::string sUri);
	void sslVerify();

    std::string m_sErrorMsg;
    CURL *m_pCurl;
    curl_slist *m_pList;
    curl_httppost *m_formpost;
    curl_httppost *m_lastptr;
    std::string m_sParmStr;
    int m_nTimeOutSecord;

    static std::once_flag oc_init;
    static std::once_flag oc_destory;
};



#endif // CHTTPCLIENT_H
