Created
May 1, 2014 07:21
-
-
Save kuetsuhara/f5b224cd225f2ac118f7 to your computer and use it in GitHub Desktop.
This file contains 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
#pragma once | |
#include "GameFramework/Actor.h" | |
#include "Http.h" | |
#include "HelloWorld.generated.h" | |
/** | |
* | |
*/ | |
UCLASS() | |
class AHelloWorld : public AActor | |
{ | |
GENERATED_UCLASS_BODY() | |
virtual void BeginPlay() OVERRIDE; | |
void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful); | |
}; |
This file contains 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
#include "UIDemo.h" | |
#include "HelloWorld.h" | |
AHelloWorld::AHelloWorld(const class FPostConstructInitializeProperties& PCIP) | |
: Super(PCIP) | |
{ | |
} | |
void AHelloWorld::BeginPlay(){ | |
Super::BeginPlay(); | |
// リクエストの作成 | |
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest(); | |
HttpRequest->SetVerb("GET"); | |
HttpRequest->SetURL("http://www.yahoo.com"); | |
// CallBack Delegateの設定 | |
HttpRequest->OnProcessRequestComplete().BindUObject(this, &AHelloWorld::OnResponseReceived); | |
// リクエスト開始 | |
HttpRequest->ProcessRequest(); | |
if (GEngine){ | |
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HelloWorld!")); | |
} | |
} | |
// CallBack Delegate | |
void AHelloWorld::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) | |
{ | |
FString MessageBody = ""; | |
// If HTTP fails client-side, this will still be called but with a NULL shared pointer! | |
if (!Response.IsValid()) | |
{ | |
MessageBody = "{\"success\":\"Error: Unable to process HTTP Request!\"}"; | |
UE_LOG(LogTemp, Warning, TEXT("Error")); | |
} | |
else if (EHttpResponseCodes::IsOk(Response->GetResponseCode())) | |
{ | |
MessageBody = Response->GetContentAsString(); | |
} | |
else | |
{ | |
MessageBody = FString::Printf(TEXT("{\"success\":\"HTTP Error: %d\"}"), Response->GetResponseCode()); | |
UE_LOG(LogTemp, Warning, TEXT("success")); | |
} | |
if (GEngine){ | |
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, MessageBody); | |
} | |
} |
This file contains 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
using UnrealBuildTool; | |
public class UIDemo : ModuleRules | |
{ | |
public UIDemo(TargetInfo Target) | |
{ | |
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); | |
PrivateDependencyModuleNames.AddRange(new string[] { "HTTP" }); | |
PrivateIncludePathModuleNames.AddRange(new string[] { "HTTP" }); | |
// Uncomment if you are using Slate UI | |
// PrivateDependencyModuleNames.Add("Slate"); | |
// Uncomment if you are using online features | |
// PrivateDependencyModuleNames.Add("OnlineSubsystem"); | |
// if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64)) | |
// { | |
// if (UEBuildConfiguration.bCompileSteamOSS == true) | |
// { | |
// DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam"); | |
// } | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment