Hello thanks for taking the time out of your day to read this!
First off I am fairly new to C++, but i have some experience in C and Java.
I am trying to implement a HttpRequest for a database connection. However I can’t even get the project to build. At first I tried to do it myself, but after it didn’t work and I wasn’t able to fix it on my own I tried following a tutorial from the wiki. However the results were the same.
HttpActor.h:
#pragma once
#include "GameFramework/Actor.h"
#include "HttpActor.generated.h"
#include "Runtime/Online/HTTP/Public/Http.h"
UCLASS()
class DBTST_API AHttpActor : public AActor
{
GENERATED_BODY()
public:
FHttpModule *http;
UFUNCTION()
void MyHttpCall();
void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
AHttpActor(const class FObjectInizializer& ObjectInitializer);
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
HttpActor.cpp:
#include "DBtst.h"
#include "HttpActor.h"
// Sets default values
AHttpActor::AHttpActor(const class FObjectInizializer& ObjectInizializer)
: Super(ObjectInizializer)
{
Http = &FHttpModule::Get();
}
// Called when the game starts or when spawned
void AHttpActor::BeginPlay()
{
MyHttpCall();
Super::BeginPlay();
}
void AHttpActor::MyHttpCall()
{
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AHttpActor::OnResponseReceived);
Request->SetURL("192.168.1.15/MySQLDatabaseUtil/test.php");
Request->SetVerb("GET");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->ProcessRequest();
}
void AHttpActor::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
int32 receivedInt = JsonObject->GetIntegerField("customInt");
GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, FString::FromInt(receivedInt));
}
}
Build.cs:
using UnrealBuildTool;
public class DBtst : ModuleRules
{
public DBtst(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Http", "Json", "JsonUtilities" });
PrivateDependencyModuleNames.AddRange(new string[] { });
}
}
Engine.ini in Saved\Config\Windows
These are all the [errors][3] I’m getting. I am pretty sure the MSB3075 error is the main problem, but I couldn’t find anything on the internet.
I would be extremely grateful if anyone on here could help me out.
Thanks in advance, !