bool FCrashUpload::SendCheckReportRequest() { FString XMLString; UE_LOG(CrashReportClientLog, Log, TEXT("Sending HTTP request (checking report)")); auto Request = CreateHttpRequest(); if (State == EUploadState::CheckingReport) { AssignReportIdToPostDataBuffer(); Request->SetURL(UrlPrefix / TEXT("CheckReport")); Request->SetHeader(TEXT("Content-Type"), TEXT("text/plain; charset=us-ascii")); } else { // This part is Windows-specific on the server ErrorReport.LoadWindowsReportXmlFile( XMLString ); // Convert the XMLString into the UTF-8. FTCHARToUTF8 Converter( (const TCHAR*)*XMLString, XMLString.Len() ); const int32 Length = Converter.Length(); PostData.Reset( Length ); PostData.AddUninitialized( Length ); CopyAssignItems( (ANSICHAR*)PostData.GetData(), Converter.Get(), Length ); Request->SetURL(UrlPrefix / TEXT("CheckReportDetail")); Request->SetHeader(TEXT("Content-Type"), TEXT("text/plain; charset=utf-8")); } UE_LOG( CrashReportClientLog, Log, TEXT( "PostData Num: %i" ), PostData.Num() ); Request->SetVerb(TEXT("POST")); Request->SetContent(PostData); return Request->ProcessRequest(); }
/** * Converts an arbitrary text buffer to an FString. * Supports all combination of ANSI/Unicode files and platforms. */ void FFileHelper::BufferToString( FString& Result, const uint8* Buffer, int32 Size ) { TArray<TCHAR>& ResultArray = Result.GetCharArray(); ResultArray.Empty(); if( Size >= 2 && !( Size & 1 ) && Buffer[0] == 0xff && Buffer[1] == 0xfe ) { // Unicode Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator. ResultArray.AddUninitialized( Size / 2 ); for( int32 i = 0; i < ( Size / 2 ) - 1; i++ ) { ResultArray[ i ] = CharCast<TCHAR>( (UCS2CHAR)(( uint16 )Buffer[i * 2 + 2] + ( uint16 )Buffer[i * 2 + 3] * 256) ); } } else if( Size >= 2 && !( Size & 1 ) && Buffer[0] == 0xfe && Buffer[1] == 0xff ) { // Unicode non-Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator. ResultArray.AddUninitialized( Size / 2 ); for( int32 i = 0; i < ( Size / 2 ) - 1; i++ ) { ResultArray[ i ] = CharCast<TCHAR>( (UCS2CHAR)(( uint16 )Buffer[i * 2 + 3] + ( uint16 )Buffer[i * 2 + 2] * 256) ); } } else { if ( Size >= 3 && Buffer[0] == 0xef && Buffer[1] == 0xbb && Buffer[2] == 0xbf ) { // Skip over UTF-8 BOM if there is one Buffer += 3; Size -= 3; } FUTF8ToTCHAR Conv((const ANSICHAR*)Buffer, Size); int32 Length = Conv.Length(); ResultArray.AddUninitialized(Length + 1); // For the null terminator CopyAssignItems(ResultArray.GetData(), Conv.Get(), Length); } if (ResultArray.Num() == 1) { // If it's only a zero terminator then make the result actually empty ResultArray.Empty(); } else { // Else ensure null terminator is present ResultArray.Last() = 0; } }