void CRTConnHttp::SendResponse(int code, const std::string&params, const char*pData, int nDataLen)
{
	http_message *httpMsg = http_generator_create(HTTP_RESPONSE);
	httpMsg->status_code = (http_status)code;

	//
	http_generator_add_header(httpMsg, HPR_ACCESS_CONTROL_ALLOW_ORIGIN, "*", 1);

	if(params.length() > 0)
	{
		http_generator_add_header(httpMsg, HPR_PRAGMA, params.c_str(), (int)params.length());
	}

	if(pData != NULL && nDataLen > 0)
	{
		http_generator_set_content(httpMsg, pData, nDataLen, "text/json");
	}

	int nLen = 0;
	char* pMsg = http_generator_tostring(httpMsg, &nLen);

	OnResponse(pMsg, nLen);

	free(pMsg);
	http_generator_destroy(httpMsg);
	httpMsg = NULL;
}
Пример #2
0
const char* RTConnHttp::GenerateRequest(http_method method, const std::string& path, const std::string& data, int &outLen) const
{
    if (path.length()==0) {
        LE("params error!!!\n");
        outLen = 0;
        return "";
    }
    
    http_message *httpMsg = http_generator_create(HTTP_REQUEST);
    
    http_generator_set_method(httpMsg, method);
    http_generator_set_path(httpMsg, path.c_str(), (int)path.length());
    http_generator_add_header(httpMsg, HPR_HOST, m_host.c_str(), (int)m_host.length());
    http_generator_add_header(httpMsg, HPR_ACCEPT, "application/json", 16);
    
    if(data.length()>0)
    {
        http_generator_set_content(httpMsg, data.c_str(), (int)data.length(), "application/x-www-form-urlencoded");
    }
    
    int nLen = 0;
    char* pMsg = http_generator_tostring(httpMsg, &nLen);
    outLen = nLen;
    
    http_generator_destroy(httpMsg);
    httpMsg = NULL;
    
    return pMsg;
}
void CRTConnHttp::SendResponse(int code, const std::string&strContent)
{
	http_message *httpMsg = http_generator_create(HTTP_RESPONSE);
	httpMsg->status_code = (http_status)code;

	//
	http_generator_add_header(httpMsg, HPR_ACCESS_CONTROL_ALLOW_ORIGIN, "*", 1);

	if(strContent.length() > 0)
	{
		http_generator_set_content(httpMsg, strContent.c_str(), (int)strContent.length(), "text/json");
	}

	int nLen = 0;
	char* pMsg = http_generator_tostring(httpMsg, &nLen);

	OnResponse(pMsg, nLen);

	free(pMsg);
	http_generator_destroy(httpMsg);
	httpMsg = NULL;
}