本文整理汇总了C++中HttpRequest::GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::GetMethod方法的具体用法?C++ HttpRequest::GetMethod怎么用?C++ HttpRequest::GetMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::GetMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessRequest
int TestServer::ProcessRequest(const HttpRequest& request, Socket& sock)
{
if(request.GetMethod()==GET)
{
std::string str=p_service->GetWSDL();
HttpResponse resp(200,str);
std::string header=resp.GetString();
sock.Send(header.c_str(),header.length());
return 1;
}
if(request.GetMethod()==POST)
{
std::string str;
int ret=Invoke(request.GetContent(),str);
int ret_code;
if(ret==1)
ret_code=200; //OK
else
ret_code=500; //internal server error
HttpResponse resp(ret_code,str);
std::string header=resp.GetString();
sock.Send(header.c_str(),header.length());
return 1;
}
return 0;
}
示例2: if
static Aws::String CanonicalizeRequestSigningString(HttpRequest& request, bool urlEscapePath)
{
request.CanonicalizeRequest();
Aws::StringStream signingStringStream;
signingStringStream << HttpMethodMapper::GetNameForHttpMethod(request.GetMethod());
//double encode paths unless explicitly stated otherwise (for s3 compatibility)
URI uriCpy = request.GetUri();
uriCpy.SetPath(uriCpy.GetURLEncodedPath());
signingStringStream << NEWLINE << (urlEscapePath ? uriCpy.GetURLEncodedPath() : uriCpy.GetPath()) << NEWLINE;
if (request.GetQueryString().size() > 1 && request.GetQueryString().find("=") != std::string::npos)
{
signingStringStream << request.GetQueryString().substr(1) << NEWLINE;
}
else if (request.GetQueryString().size() > 1)
{
signingStringStream << request.GetQueryString().substr(1) << "=" << NEWLINE;
}
else
{
signingStringStream << NEWLINE;
}
return signingStringStream.str();
}
示例3: SetOptCodeForHttpMethod
void SetOptCodeForHttpMethod(CURL* requestHandle, const HttpRequest& request)
{
switch (request.GetMethod())
{
case HttpMethod::HTTP_GET:
curl_easy_setopt(requestHandle, CURLOPT_HTTPGET, 1L);
break;
case HttpMethod::HTTP_POST:
if (!request.HasHeader(Aws::Http::CONTENT_LENGTH_HEADER)|| request.GetHeaderValue(Aws::Http::CONTENT_LENGTH_HEADER) == "0")
{
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "POST");
}
else
{
curl_easy_setopt(requestHandle, CURLOPT_POST, 1L);
}
break;
case HttpMethod::HTTP_PUT:
if (!request.HasHeader(Aws::Http::CONTENT_LENGTH_HEADER) || request.GetHeaderValue(Aws::Http::CONTENT_LENGTH_HEADER) == "0")
{
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "PUT");
}
else
{
curl_easy_setopt(requestHandle, CURLOPT_PUT, 1L);
}
break;
case HttpMethod::HTTP_HEAD:
curl_easy_setopt(requestHandle, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(requestHandle, CURLOPT_NOBODY, 1L);
break;
case HttpMethod::HTTP_PATCH:
if (!request.HasHeader(Aws::Http::CONTENT_LENGTH_HEADER)|| request.GetHeaderValue(Aws::Http::CONTENT_LENGTH_HEADER) == "0")
{
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "PATCH");
}
else
{
curl_easy_setopt(requestHandle, CURLOPT_POST, 1L);
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "PATCH");
}
break;
case HttpMethod::HTTP_DELETE:
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
//curl_easy_setopt(requestHandle, CURLOPT_NOBODY, 1L);
break;
default:
assert(0);
curl_easy_setopt(requestHandle, CURLOPT_CUSTOMREQUEST, "GET");
break;
}
}
示例4: CanonicalizeRequestSigningString
Aws::String CanonicalizeRequestSigningString(HttpRequest& request)
{
request.CanonicalizeRequest();
Aws::StringStream signingStringStream;
signingStringStream << HttpMethodMapper::GetNameForHttpMethod(request.GetMethod());
signingStringStream << NEWLINE << request.GetUri().GetURLEncodedPath() << NEWLINE;
if (request.GetQueryString().size() > 1 && request.GetQueryString().find("=") != std::string::npos)
{
signingStringStream << request.GetQueryString().substr(1) << NEWLINE;
}
else if (request.GetQueryString().size() > 1)
{
signingStringStream << request.GetQueryString().substr(1) << "=" << NEWLINE;
}
else
{
signingStringStream << NEWLINE;
}
return signingStringStream.str();
}
示例5: if
std::shared_ptr<HttpResponse> WinSyncHttpClient::MakeRequest(HttpRequest& request,
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter,
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter) const
{
//we URL encode right before going over the wire to avoid double encoding problems with the signer.
URI& uriRef = request.GetUri();
uriRef.SetPath(URI::URLEncodePath(uriRef.GetPath()));
AWS_LOGSTREAM_TRACE(GetLogTag(), "Making " << HttpMethodMapper::GetNameForHttpMethod(request.GetMethod()) <<
" request to uri " << uriRef.GetURIString(true));
bool success = IsRequestProcessingEnabled();
void* connection = nullptr;
void* hHttpRequest = nullptr;
if(success)
{
if (writeLimiter != nullptr)
{
writeLimiter->ApplyAndPayForCost(request.GetSize());
}
connection = m_connectionPoolMgr->AquireConnectionForHost(uriRef.GetAuthority(), uriRef.GetPort());
AWS_LOGSTREAM_DEBUG(GetLogTag(), "Acquired connection " << connection);
hHttpRequest = AllocateWindowsHttpRequest(request, connection);
AddHeadersToRequest(request, hHttpRequest);
success = DoSendRequest(hHttpRequest);
}
if(success)
{
success = StreamPayloadToRequest(request, hHttpRequest);
}
std::shared_ptr<HttpResponse> response(nullptr);
if(success)
{
response = BuildSuccessResponse(request, hHttpRequest, readLimiter);
}
else if (!IsRequestProcessingEnabled())
{
AWS_LOG_INFO(GetLogTag(), "Request cancelled by client controller");
}
else
{
LogRequestInternalFailure();
}
if (hHttpRequest)
{
AWS_LOGSTREAM_DEBUG(GetLogTag(), "Closing http request handle " << hHttpRequest);
GetConnectionPoolManager()->DoCloseHandle(hHttpRequest);
}
AWS_LOGSTREAM_DEBUG(GetLogTag(), "Releasing connection handle " << connection);
GetConnectionPoolManager()->ReleaseConnectionForHost(request.GetUri().GetAuthority(), request.GetUri().GetPort(), connection);
return response;
}
示例6: writeContext
//.........这里部分代码省略.........
#if LIBCURL_VERSION_MAJOR >= 7
#if LIBCURL_VERSION_MINOR >= 34
curl_easy_setopt(connectionHandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
#endif //LIBCURL_VERSION_MINOR
#endif //LIBCURL_VERSION_MAJOR
}
else
{
curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(connectionHandle, CURLOPT_SSL_VERIFYHOST, 0L);
}
if (m_allowRedirects)
{
curl_easy_setopt(connectionHandle, CURLOPT_FOLLOWLOCATION, 1L);
}
else
{
curl_easy_setopt(connectionHandle, CURLOPT_FOLLOWLOCATION, 0L);
}
//curl_easy_setopt(connectionHandle, CURLOPT_VERBOSE, 1);
//curl_easy_setopt(connectionHandle, CURLOPT_DEBUGFUNCTION, CurlDebugCallback);
if (m_isUsingProxy)
{
curl_easy_setopt(connectionHandle, CURLOPT_PROXY, m_proxyHost.c_str());
curl_easy_setopt(connectionHandle, CURLOPT_PROXYPORT, (long) m_proxyPort);
curl_easy_setopt(connectionHandle, CURLOPT_PROXYUSERNAME, m_proxyUserName.c_str());
curl_easy_setopt(connectionHandle, CURLOPT_PROXYPASSWORD, m_proxyPassword.c_str());
}
else
{
curl_easy_setopt(connectionHandle, CURLOPT_PROXY, "");
}
if (request.GetContentBody())
{
curl_easy_setopt(connectionHandle, CURLOPT_READFUNCTION, &CurlHttpClient::ReadBody);
curl_easy_setopt(connectionHandle, CURLOPT_READDATA, &readContext);
}
CURLcode curlResponseCode = curl_easy_perform(connectionHandle);
bool shouldContinueRequest = ContinueRequest(request);
if (curlResponseCode != CURLE_OK && shouldContinueRequest)
{
response = nullptr;
AWS_LOGSTREAM_ERROR(CURL_HTTP_CLIENT_TAG, "Curl returned error code " << curlResponseCode);
}
else if(!shouldContinueRequest)
{
response->SetResponseCode(HttpResponseCode::REQUEST_NOT_MADE);
}
else
{
long responseCode;
curl_easy_getinfo(connectionHandle, CURLINFO_RESPONSE_CODE, &responseCode);
response->SetResponseCode(static_cast<HttpResponseCode>(responseCode));
AWS_LOGSTREAM_DEBUG(CURL_HTTP_CLIENT_TAG, "Returned http response code " << responseCode);
char* contentType = nullptr;
curl_easy_getinfo(connectionHandle, CURLINFO_CONTENT_TYPE, &contentType);
if (contentType)
{
response->SetContentType(contentType);
AWS_LOGSTREAM_DEBUG(CURL_HTTP_CLIENT_TAG, "Returned content type " << contentType);
}
if (request.GetMethod() != HttpMethod::HTTP_HEAD &&
writeContext.m_client->IsRequestProcessingEnabled() &&
response->HasHeader(Aws::Http::CONTENT_LENGTH_HEADER))
{
const Aws::String& contentLength = response->GetHeader(Aws::Http::CONTENT_LENGTH_HEADER);
int64_t numBytesResponseReceived = writeContext.m_numBytesResponseReceived;
AWS_LOGSTREAM_TRACE(CURL_HTTP_CLIENT_TAG, "Response content-length header: " << contentLength);
AWS_LOGSTREAM_TRACE(CURL_HTTP_CLIENT_TAG, "Response body length: " << numBytesResponseReceived);
if (StringUtils::ConvertToInt64(contentLength.c_str()) != numBytesResponseReceived)
{
response = nullptr;
AWS_LOG_ERROR(CURL_HTTP_CLIENT_TAG, "Response body length doesn't match the content-length header.");
}
}
AWS_LOGSTREAM_DEBUG(CURL_HTTP_CLIENT_TAG, "Releasing curl handle " << connectionHandle);
}
m_curlHandleContainer.ReleaseCurlHandle(connectionHandle);
//go ahead and flush the response body stream
if(response)
{
response->GetResponseBody().flush();
}
}
if (headers)
{
curl_slist_free_all(headers);
}
return response;
}