-
-
Save InternetCube/415693cede8a438122a31b7ffbde02ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool AExampleActor::Request() | |
| { | |
| const TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest(); | |
| HttpRequest->SetVerb(TEXT("GET")); | |
| HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/octet-stream")); | |
| HttpRequest->SetURL(/*何かしらの通信を行う先のURL*/); | |
| HttpRequest->OnProcessRequestComplete().BindUObject(this, &AExampleActor::OnReceived); | |
| return HttpRequest->ProcessRequest(); | |
| } | |
| void AExampleActor::OnReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccessful); | |
| { | |
| bool bIsSuccess = false; | |
| // ON_SCOPE_EXIT内に書かれた処理はこの関数のスコープを抜ける際に呼び出される | |
| ON_SCOPE_EXIT | |
| { | |
| if (!bIsSuccess && OnFailure.IsBound()) | |
| { | |
| OnFailure.Broadcast(); | |
| } | |
| }; | |
| if (!Request.IsValid()) | |
| { | |
| return; | |
| } | |
| if (!Response.IsValid()) | |
| { | |
| return; | |
| } | |
| if (Response->GetResponseCode() != EHttpResponseCodes::Ok) | |
| { | |
| return; | |
| } | |
| if (!bSuccessful) | |
| { | |
| return; | |
| } | |
| // Request成功時にbIsSuccessのフラグを立てることで失敗時のCallback呼び出しを抑制 | |
| bIsSuccess = true; | |
| // Request成功時の処理 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment