本文整理汇总了C++中FHttpResponsePtr::GetContentAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ FHttpResponsePtr::GetContentAsString方法的具体用法?C++ FHttpResponsePtr::GetContentAsString怎么用?C++ FHttpResponsePtr::GetContentAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FHttpResponsePtr
的用法示例。
在下文中一共展示了FHttpResponsePtr::GetContentAsString方法的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: 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;
}
示例3: 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());
}
}
示例4: 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());
}
}
示例5: 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());
}
}
示例6: 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);
}
示例7: ParseServerResponse
bool FCrashUpload::ParseServerResponse(FHttpResponsePtr Response)
{
// Turn the snippet into a complete XML document, to keep the XML parser happy
FXmlFile ParsedResponse(FString(TEXT("<Root>")) + Response->GetContentAsString() + TEXT("</Root>"), EConstructMethod::ConstructFromBuffer);
UE_LOG(CrashReportClientLog, Log, TEXT("Response->GetContentAsString(): '%s'"), *Response->GetContentAsString());
if (!ParsedResponse.IsValid())
{
UE_LOG(CrashReportClientLog, Log, TEXT("Invalid response!"));
return false;
}
if (auto ResultNode = ParsedResponse.GetRootNode()->FindChildNode(TEXT("CrashReporterResult")))
{
UE_LOG(CrashReportClientLog, Log, TEXT("ResultNode->GetAttribute(TEXT(\"bSuccess\")) = %s"), *ResultNode->GetAttribute(TEXT("bSuccess")));
return ResultNode->GetAttribute(TEXT("bSuccess")) == TEXT("true");
}
UE_LOG(CrashReportClientLog, Log, TEXT("Could not find CrashReporterResult"));
return false;
}
示例8: HTTPOnResponseReceived
void AVictoryPC::HTTPOnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
FString ResponseStr = "AVictoryPC::HTTPOnResponseReceived>>> Connection Error";
if(bWasSuccessful)
{
ResponseStr = Response->GetContentAsString();
}
this->VictoryPC_GetMyIP_DataReceived(ResponseStr);
}
示例9: ReadFile_HttpRequestComplete
void FSurveyTitleCdnStorage::ReadFile_HttpRequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
bool bResult = false;
FString ResponseStr, ErrorStr;
// should have a pending Http request
FPendingFileRequest PendingRequest = FileRequests.FindChecked(HttpRequest.Get());
FileRequests.Remove(HttpRequest.Get());
// Cloud file being operated on
FCloudFile* CloudFile = GetCloudFile(PendingRequest.FileName, true);
CloudFile->AsyncState = EOnlineAsyncTaskState::Failed;
CloudFile->Data.Empty();
if (bSucceeded &&
HttpResponse.IsValid())
{
if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
UE_LOG(LogEpicSurvey, Verbose, TEXT("ReadFile request complete. url=%s code=%d"),
*HttpRequest->GetURL(), HttpResponse->GetResponseCode());
// update the memory copy of the file with data that was just downloaded
CloudFile = GetCloudFile(PendingRequest.FileName, true);
CloudFile->AsyncState = EOnlineAsyncTaskState::Done;
CloudFile->Data = HttpResponse->GetContent();
// cache to disk on successful download
SaveCloudFileToDisk(CloudFile->FileName,CloudFile->Data);
bResult = true;
}
else
{
ErrorStr = FString::Printf(TEXT("Invalid response. code=%d error=%s"),
HttpResponse->GetResponseCode(), *HttpResponse->GetContentAsString());
}
}
else
{
ErrorStr = TEXT("No response");
}
if (!ErrorStr.IsEmpty())
{
UE_LOG(LogEpicSurvey, Verbose, TEXT("ReadFile request failed. %s"), *ErrorStr);
}
TriggerOnReadFileCompleteDelegates(bResult, PendingRequest.FileName);
}
示例10: OnReady
/**
* Callback for IHttpRequest::OnProcessRequestComplete()
*
* @param Request HTTP request pointer
* @param Response Response pointer
* @param bWasSuccessful Whether the request was successful or not
*
*/
void UJsonFieldData::OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
if (!bWasSuccessful) {
UE_LOG(LogJson, Error, TEXT("Response was invalid! Please check the URL."));
// Broadcast the failed event
OnFailed.Broadcast();
return;
}
// Process the string
FromString(Response->GetContentAsString());
// Broadcast the result event
OnGetResult.Broadcast();
}
示例11: AccountInfo_Response
void FSimplygonRESTClient::AccountInfo_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("Account info response: %s"), *msg);
}
else
{
SwarmTask->SetState(SRS_FAILED);
UE_LOG(LogSimplygonRESTClient, Warning, TEXT("Account info response: %i"), Response->GetResponseCode());
}
}
示例12: ParseMessageFromResponse
bool HttpRpcRequest::ParseMessageFromResponse(FHttpResponsePtr response) {
const FString contentType = response->GetContentType();
if (contentType.StartsWith(kContentTypeJson)) {
} else if (contentType.StartsWith(kContentTypeASCII)) {
if (!google::protobuf::TextFormat::ParseFromString(TCHAR_TO_UTF8(*response->GetContentAsString()), callState_.GetResponse())) {
UE_LOG(HttpRpcRequestLog, Error, TEXT("ASCII response parse failed"));
return false;
}
return true;
} else if (contentType.StartsWith(kContentTypeBinary)) {
} else {
UE_LOG(HttpRpcRequestLog, Error, TEXT("Invalid content type '%s'"), *contentType);
}
return false;
}
示例13: RequestComplete
void FHttpTest::RequestComplete(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded)
{
if (!HttpResponse.IsValid())
{
UE_LOG(LogHttp, Log, TEXT("Test failed. NULL response"));
}
else
{
UE_LOG(LogHttp, Log, TEXT("Completed test [%s] Url=[%s] Response=[%d] [%s]"),
*HttpRequest->GetVerb(),
*HttpRequest->GetURL(),
HttpResponse->GetResponseCode(),
*HttpResponse->GetContentAsString());
}
if ((--TestsToRun) <= 0)
{
HttpRequest->OnProcessRequestComplete().Unbind();
// Done with the test. Delegate should always gets called
delete this;
}
}
示例14: OnGetResponseComplete
/**
* Callback function for MakeRequest. Sets the global response variable.
*
* @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::OnGetResponseComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(CloudyWebAPILog, Warning, TEXT("Response Code = %d"), Response->GetResponseCode());
if (Response.IsValid() && EHttpResponseCodes::IsOk(Response->GetResponseCode()))
{
HttpResponse = Response->GetContentAsString();
}
else
{
UE_LOG(CloudyWebAPILog, Warning, TEXT("Request failed! Response invalid"));
}
}
else
{
UE_LOG(CloudyWebAPILog, Warning, TEXT("Request failed! Is the server up?"));
}
}
示例15: DeserializeResponseToStruct
static bool DeserializeResponseToStruct(void* OutStruct, UStruct& TypeInfo, FHttpResponsePtr HttpResponse)
{
bool bResult = false;
FString ResponseStr = HttpResponse->GetContentAsString();
FText ErrorText;
if (HttpResponse.IsValid())
{
if (EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode()))
{
// Write string to FMemoryWriter to force unicode
TArray<uint8> InBytes;
FMemoryWriter Writer(InBytes);
Writer.ArForceUnicode = true;
Writer << ResponseStr;
FMemoryReader Reader(InBytes);
// FMemoryWriter writes size of string at beginning, need to ignore this or json parsing errors occur
Reader.Seek(4);
FJsonStructDeserializerBackend Backend(Reader);
bResult = FStructDeserializer::Deserialize(OutStruct, TypeInfo, Backend);
}
else
{
ErrorText = FText::Format(LOCTEXT("InvalidResponse", "Invalid response. code={0} error={1}"), FText::FromString(FString::FromInt(HttpResponse->GetResponseCode())), FText::FromString(ResponseStr));
}
}
if (!bResult)
{
UE_LOG(LogLocalizationService, Warning, TEXT("%s"), *(ErrorText.ToString()));
}
return bResult;
}