本文整理汇总了C++中FHttpResponsePtr类的典型用法代码示例。如果您正苦于以下问题:C++ FHttpResponsePtr类的具体用法?C++ FHttpResponsePtr怎么用?C++ FHttpResponsePtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FHttpResponsePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleLightStateRequestComplete
void UPhilipsHueBridge::HandleLightStateRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
FString MessageBody = "";
if (!HttpResponse.IsValid())
{
MessageBody = "{\"success\":\"Error: Unable to process HTTP Request!\"}";
}
else if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
MessageBody = HttpResponse->GetContentAsString();
int32 idx = MessageBody.Find("error");
if (idx > 0){
//Send Error;
}
else
{
//Successfully sent!
}
}
else
{
MessageBody = FString::Printf(TEXT("{\"success\":\"HTTP Error: %d\"}"), HttpResponse->GetResponseCode());
}
}
示例2: OnAuthResponseComplete
/**
* This is a callback function that is called when the "AttemptAuthentication" function
* has completed its request.
*
* @param Request
* @param Response Contains the data of the response, including the response code.
* @param bWasSuccessful Contains true if the request was successful. Else it contains false.
*
*/
void CloudyWebAPIImpl::OnAuthResponseComplete(FHttpRequestPtr Request,
FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(CloudyWebAPILog, Warning, TEXT("Response Code = %d"), Response->GetResponseCode());
if (!Response.IsValid())
{
UE_LOG(CloudyWebAPILog, Warning, TEXT("Request failed!"));
}
else if (EHttpResponseCodes::IsOk(Response->GetResponseCode()))
{
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(Response->GetContentAsString());
FJsonSerializer::Deserialize(JsonReader, JsonObject);
Token = JsonObject->GetStringField("token");
UE_LOG(CloudyWebAPILog, Warning, TEXT("Token = %s"), *Token);
}
}
else
{
UE_LOG(CloudyWebAPILog, Error, TEXT("Request failed! Is the server up?"));
}
}
示例3: DownloadAsset_Response
void FSimplygonRESTClient::DownloadAsset_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (!Response.IsValid())
{
SwarmTask->SetState(SRS_FAILED);
}
else if (EHttpResponseCodes::IsOk(Response->GetResponseCode()))
{
TArray<uint8> data = Response->GetContent();
if (!FFileHelper::SaveArrayToFile(data, *SwarmTask->OutputFilename))
{
UE_LOG(LogSimplygonRESTClient, Log, TEXT("Unable to save file %S"), *SwarmTask->OutputFilename);
SwarmTask->SetState(SRS_FAILED);
}
else
{
SwarmTask->OnAssetDownloaded().ExecuteIfBound(*SwarmTask);
SwarmTask->SetState(SRS_ASSETDOWNLOADED);
UE_LOG(LogSimplygonRESTClient, Log, TEXT("Asset downloaded"));
}
}
else
{
SwarmTask->SetState(SRS_FAILED);
UE_LOG(LogSimplygonRESTClient, Warning, TEXT("Response: %i"), Response->GetResponseCode());
}
}
示例4: HttpDownloadHeaderFinished
void FHttpNetworkReplayStreamer::HttpDownloadHeaderFinished( FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded )
{
check( HttpState == EHttptate::DownloadingHeader );
check( StreamerState == EStreamerState::NeedToDownloadHeader );
check( StreamArchive.IsLoading() );
HttpState = EHttptate::Idle;
if ( bSucceeded && HttpResponse->GetResponseCode() == EHttpResponseCodes::Ok )
{
HeaderArchive.Buffer.Append( HttpResponse->GetContent() );
UE_LOG( LogHttpReplay, Log, TEXT( "FHttpNetworkReplayStreamer::HttpDownloadHeaderFinished. Size: %i" ), HeaderArchive.Buffer.Num() );
StartStreamingDelegate.ExecuteIfBound( true, StreamArchive.IsSaving() );
StreamerState = EStreamerState::StreamingDown;
}
else
{
// FAIL
UE_LOG( LogHttpReplay, Error, TEXT( "FHttpNetworkReplayStreamer::HttpDownloadHeaderFinished. FAILED." ) );
StreamArchive.Buffer.Empty();
StartStreamingDelegate.ExecuteIfBound( false, StreamArchive.IsSaving() );
SetLastError( ENetworkReplayError::ServiceUnavailable );
}
// Reset delegate
StartStreamingDelegate = FOnStreamReadyDelegate();
}
示例5: if
bool FHttpRetrySystem::FManager::ShouldRetry(const FHttpRetryRequestEntry& HttpRetryRequestEntry)
{
bool bResult = false;
FHttpResponsePtr Response = HttpRetryRequestEntry.Request->GetResponse();
// invalid response means connection or network error but we need to know which one
if (!Response.IsValid())
{
// ONLY retry bad responses if they are connection errors (NOT protocol errors or unknown) otherwise request may be sent (and processed!) twice
EHttpRequestStatus::Type Status = HttpRetryRequestEntry.Request->GetStatus();
if (Status == EHttpRequestStatus::Failed_ConnectionError)
{
bResult = true;
}
else if (Status == EHttpRequestStatus::Failed)
{
// we will also allow retry for GET and HEAD requests even if they may duplicate on the server
FString Verb = HttpRetryRequestEntry.Request->GetVerb();
if (Verb == TEXT("GET") || Verb == TEXT("HEAD"))
{
bResult = true;
}
}
}
else
{
// this may be a successful response with one of the explicitly listed response codes we want to retry on
if (HttpRetryRequestEntry.Request->RetryResponseCodes.Contains(Response->GetResponseCode()))
{
bResult = true;
}
}
return bResult;
}
示例6: HandleUserIDTestRequestComplete
void UPhilipsHueBridge::HandleUserIDTestRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
FString MessageBody = "";
// If HTTP fails client-side, this will still be called but with a NULL shared pointer!
if (!HttpResponse.IsValid())
{
MessageBody = "{\"success\":\"Error: Unable to process HTTP Request!\"}";
}
else if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
MessageBody = HttpResponse->GetContentAsString();
int32 idx = MessageBody.Find("unauthorized user");
if (idx > 0){
//Remind push linking
OnPushLinkRequested.Broadcast(Id);
//AquireUserID(false);
}
else
{
Connected = true;
// Successfully tested the user id
OnHueUserAuthorized.Broadcast(ConnectedUser);
}
}
else
{
MessageBody = FString::Printf(TEXT("{\"success\":\"HTTP Error: %d\"}"), HttpResponse->GetResponseCode());
}
}
示例7: OnHeliosRequestComplete
void UHeliosGetterProxy_Float::OnHeliosRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded) {
if (!bSucceeded) {
UE_LOG(LogTemp, Error, TEXT("Helios > request failed: %s"), *HttpRequest->GetURL());
OnFail.Broadcast(0);
return;
}
if (!HttpResponse.IsValid()) {
UE_LOG(LogTemp, Warning, TEXT("Helios > invalid response for request: %s"), *HttpRequest->GetURL());
OnFail.Broadcast(0);
return;
}
FString ContentAsString = HttpResponse->GetContentAsString();
json Content = json::parse(TCHAR_TO_UTF8(*ContentAsString));
if (Content.size() != 1) {
UE_LOG(LogTemp, Warning, TEXT("Helios > invalid json returned"));
OnFail.Broadcast(0);
return;
}
if (!Content["value"].is_number_float()) {
UE_LOG(LogTemp, Warning, TEXT("Helios > invalid type returned"));
OnFail.Broadcast(0);
return;
}
float Result = Content["value"];
OnSuccess.Broadcast(Result);
}
示例8: UploadAsset_Response
void FSimplygonRESTClient::UploadAsset_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (!Response.IsValid())
{
SwarmTask->SetState(SRS_FAILED);
}
else if (EHttpResponseCodes::IsOk(Response->GetResponseCode()))
{
FString msg = Response->GetContentAsString();
UE_LOG(LogSimplygonRESTClient, Log, TEXT("Upload asset response: %s"), *msg);
TSharedPtr<FJsonObject> JsonParsed;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(msg);
if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{
SwarmTask->InputAssetId = JsonParsed->GetStringField("AssetId");
UE_LOG(LogSimplygonRESTClient, Log, TEXT("AssetId: %s"), *SwarmTask->InputAssetId);
}
SwarmTask->SetState(SRS_ASSETUPLOADED);
}
else
{
SwarmTask->SetState(SRS_FAILED);
UE_LOG(LogSimplygonRESTClient, Warning, TEXT("Response: %i"), Response->GetResponseCode());
}
}
示例9:
void FHttpServiceTracker::EndpointMetrics::TrackRequest(const FHttpRequestPtr& HttpRequest)
{
// keep a histogram of response codes
const FHttpResponsePtr HttpResponse = HttpRequest->GetResponse();
const int32 ResponseCode = HttpResponse.IsValid() ? HttpResponse->GetResponseCode() : 0;
// track all responses in a histogram
ResponseCodes.FindOrAdd(ResponseCode)++;
const float ElapsedTime = HttpRequest->GetElapsedTime();
const int64 DownloadBytes = HttpRequest->GetResponse()->GetContent().Num();
// track successes/fails separately
if (IsSuccessfulResponse(ResponseCode))
{
++SuccessCount;
// sum elapsed time for average calc
ElapsedTimeSuccessTotal += ElapsedTime;
ElapsedTimeSuccessMax = FMath::Max(ElapsedTimeSuccessMax, ElapsedTime);
ElapsedTimeSuccessMin = FMath::Min(ElapsedTimeSuccessMin, ElapsedTime);
// sum download rate for average calc
DownloadBytesSuccessTotal += DownloadBytes;
}
else
{
++FailCount;
// sum elapsed time for average calc
ElapsedTimeFailTotal += ElapsedTime;
ElapsedTimeFailMax = FMath::Max(ElapsedTimeFailMax, ElapsedTime);
ElapsedTimeFailMin = FMath::Min(ElapsedTimeFailMin, ElapsedTime);
// sum download rate for average calc
DownloadBytesFailTotal += DownloadBytes;
}
}
示例10: HandleUserIDRequestComplete
void UPhilipsHueBridge::HandleUserIDRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
FString MessageBody = "";
FString userid = "";
// If HTTP fails client-side, this will still be called but with a NULL shared pointer!
if (!HttpResponse.IsValid())
{
MessageBody = "{\"success\":\"Error: Unable to process HTTP Request!\"}";
}
else if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
MessageBody = HttpResponse->GetContentAsString();
TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(*MessageBody);
int32 idx = MessageBody.Find("\"username\"");
if (idx > 0){
userid = MessageBody.Trim();
userid.RemoveFromStart("[{\"success\":{\"username\":\"");
userid.RemoveFromEnd("\"}}]");
ConnectedUser = userid;
SaveUserIDToFile();
OnHueUserAuthorized.Broadcast(userid);
}
else
{
OnPushLinkRequested.Broadcast(Id);
}
}
else
{
MessageBody = FString::Printf(TEXT("{\"success\":\"HTTP Error: %d\"}"), HttpResponse->GetResponseCode());
}
}
示例11: PyErr_Format
static PyObject *py_ue_ihttp_request_get_response(ue_PyIHttpRequest *self, PyObject * args)
{
FHttpResponsePtr response = self->http_request->GetResponse();
if (!response.IsValid())
{
return PyErr_Format(PyExc_Exception, "unable to retrieve IHttpResponse");
}
return py_ue_new_ihttp_response(response.Get());
}
示例12:
bool FHttpRetrySystem::FManager::ShouldRetry(const FHttpRetryRequestEntry& HttpRetryRequestEntry)
{
bool bResult = false;
FHttpResponsePtr Response = HttpRetryRequestEntry.HttpRequest->GetResponse();
if (!Response.IsValid() || Response->GetResponseCode() == 0)
{
bResult = true;
}
return bResult;
}
示例13: DecodeRequest
bool PlayFabRequestHandler::DecodeRequest(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded, PlayFab::FPlayFabBaseModel& OutResult, PlayFab::FPlayFabError& OutError)
{
PlayFabRequestHandler::pendingCalls -= 1;
FString ResponseStr, ErrorStr;
if (bSucceeded && HttpResponse.IsValid())
{
if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
// Create the Json parser
ResponseStr = HttpResponse->GetContentAsString();
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(ResponseStr);
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
if (PlayFabRequestHandler::DecodeError(JsonObject, OutError))
{
return false;
}
const TSharedPtr<FJsonObject>* DataJsonObject;
if (JsonObject->TryGetObjectField(TEXT("data"), DataJsonObject))
{
return OutResult.readFromValue(*DataJsonObject);
}
}
}
else
{
// Create the Json parser
ResponseStr = HttpResponse->GetContentAsString();
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(ResponseStr);
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
if (PlayFabRequestHandler::DecodeError(JsonObject, OutError))
{
return false;
}
}
}
}
// If we get here, we failed to connect meaningfully to the server - Assume a timeout
OutError.HttpCode = 408;
OutError.ErrorCode = PlayFabErrorConnectionTimeout;
// For text returns, use the non-json response if possible, else default to no response
OutError.ErrorName = OutError.ErrorMessage = OutError.HttpStatus = TEXT("Request Timeout or null response");
return false;
}
示例14: HttpStartDownloadingFinished
void FHttpNetworkReplayStreamer::HttpStartDownloadingFinished( FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded )
{
check( HttpState == EHttptate::StartDownloading );
check( StreamerState == EStreamerState::NeedToDownloadHeader );
HttpState = EHttptate::Idle;
if ( bSucceeded && HttpResponse->GetResponseCode() == EHttpResponseCodes::Ok )
{
FString NumChunksString = HttpResponse->GetHeader( TEXT( "NumChunks" ) );
FString DemoTimeString = HttpResponse->GetHeader( TEXT( "Time" ) );
FString State = HttpResponse->GetHeader( TEXT( "State" ) );
ViewerName = HttpResponse->GetHeader( TEXT( "Viewer" ) );
bStreamIsLive = State == TEXT( "Live" );
NumDownloadChunks = FCString::Atoi( *NumChunksString );
DemoTimeInMS = FCString::Atoi( *DemoTimeString );
UE_LOG( LogHttpReplay, Log, TEXT( "FHttpNetworkReplayStreamer::HttpStartDownloadingFinished. Viewer: %s, State: %s, NumChunks: %i, DemoTime: %2.2f" ), *ViewerName, *State, NumDownloadChunks, (float)DemoTimeInMS / 1000 );
// First, download the header
if ( NumDownloadChunks > 0 )
{
StreamerState = EStreamerState::NeedToDownloadHeader;
}
else
{
UE_LOG( LogHttpReplay, Warning, TEXT( "FHttpNetworkReplayStreamer::HttpStartDownloadingFinished. NO CHUNKS" ) );
StartStreamingDelegate.ExecuteIfBound( false, StreamArchive.IsSaving() );
// Reset delegate
StartStreamingDelegate = FOnStreamReadyDelegate();
SetLastError( ENetworkReplayError::ServiceUnavailable );
}
}
else
{
UE_LOG( LogHttpReplay, Error, TEXT( "FHttpNetworkReplayStreamer::HttpStartDownloadingFinished. FAILED" ) );
StartStreamingDelegate.ExecuteIfBound( false, StreamArchive.IsSaving() );
// Reset delegate
StartStreamingDelegate = FOnStreamReadyDelegate();
SetLastError( ENetworkReplayError::ServiceUnavailable );
}
}
示例15:
bool FHttpRetrySystem::FManager::ShouldRetry(const FHttpRetryRequestEntry& HttpRetryRequestEntry)
{
bool bResult = false;
FHttpResponsePtr Response = HttpRetryRequestEntry.HttpRequest->GetResponse();
if (!Response.IsValid() ||
Response->GetResponseCode() == 0 ||
HttpRetryRequestEntry.HttpRequest->RetryResponseCodesOverride.Contains(Response->GetResponseCode()) ||
RetryResponseCodesDefault.Contains(Response->GetResponseCode()))
{
bResult = true;
}
return bResult;
}