Skip to content

Instantly share code, notes, and snippets.

@kuetsuhara
Created May 1, 2014 07:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuetsuhara/f5b224cd225f2ac118f7 to your computer and use it in GitHub Desktop.
Save kuetsuhara/f5b224cd225f2ac118f7 to your computer and use it in GitHub Desktop.
#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);
};
#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);
}
}
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