Exemplo n.º 1
0
void HttpRequest::send(const char* data)
{
	header_list_ = NULL;
	// combine header
	std::string sHeader;
	HEADERS::const_iterator it = request_headers_.begin();
	for(; it != request_headers_.end(); it++) {
		sHeader = it->first + ":\t";
		sHeader += it->second;
		header_list_ = curl_slist_append(header_list_, sHeader.c_str());
	}
	curl_easy_setopt(curl_, CURLOPT_HTTPHEADER, header_list_);
	
	if(data) {
		post_data_ = data;
		curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, post_data_.c_str());
		curl_easy_setopt(curl_, CURLOPT_POSTFIELDSIZE, post_data_.size());
	}

	// set request cookie
	http_manager_->GetCookies(url_, cookie_data_);
	if(!cookie_data_.empty()) 
		curl_easy_setopt(curl_, CURLOPT_COOKIE, cookie_data_.c_str());

	http_manager_->addTask(this);
}
Exemplo n.º 2
0
void http::set_header( HEADERS& headers, const std::string& field_name, const std::string& field_value )
{
    HEADERS::iterator it = headers.begin(), it_end = headers.end();
    for ( ; it!=it_end; it++ )
    {
        HEADER& header = *it;
        if ( header.field_name == field_name )
        {
            if ( field_value.empty() )
            {
                headers.erase(it);
            }
            else
            {
                header.field_value = field_value;
            }
            return;
        }
    }

    HEADER new_header;
    new_header.field_name   = field_name;
    new_header.field_value  = field_value;
    headers.push_back( new_header );
}
Exemplo n.º 3
0
std::string http::get_header( const HEADERS& headers, const std::string& field_name )
{
    HEADERS::const_iterator it = headers.begin(), it_end = headers.end();
    for ( ; it!=it_end; it++ )
    {
        const HEADER& header = *it;
        if ( header.field_name == field_name )
        {
            return header.field_value;
        }
    }
    return std::string();
}
Exemplo n.º 4
0
void http::del_header( HEADERS& headers, const std::string& field_name )
{
    HEADERS::iterator it = headers.begin(), it_end = headers.end();
    for ( ; it!=it_end; it++ )
    {
        HEADER& header = *it;
        if ( header.field_name == field_name )
        {
            headers.erase(it);
            return;
        }
    }
}