コード例 #1
0
WebRequest::WebRequest(Context* context, const String& verb, const String& url, double requestContentSize) :
    Object(context),
    is_(new WebRequestInternalState(*this))
{
    is_->url = url.Trimmed();
    is_->verb = verb;
    is_->upload = new BufferQueue(context);
    is_->download = new BufferQueue(context);
    is_->state = HTTP_INITIALIZING;
    is_->curlm = NULL;
    is_->curl = NULL;
    is_->requestContentSize = curl_off_t(std::floor(requestContentSize));
    is_->isAborted = false;
    is_->isAddedToMulti = false;

}
コード例 #2
0
Response * CURLSession::post(const POSTRequest & request) {
	
	setup(request);
	
	struct curl_slist * headers = NULL;
	BOOST_SCOPE_EXIT((headers)) {
		if(headers) {
			curl_slist_free_all(headers);
		}
	} BOOST_SCOPE_EXIT_END
	if(m_curl) {
		curl_easy_setopt(m_curl, CURLOPT_POST, 1L);
		curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, request.data().c_str());
		curl_easy_setopt(m_curl, CURLOPT_INFILESIZE_LARGE, curl_off_t(request.data().size()));
		if(!request.contentType().empty()) {
			std::string header = "Content-Type: " + request.contentType();
			headers = curl_slist_append(headers, header.c_str());
			curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headers);
		}
	}
	
	return perform(request);
}