Http Request 4.18

.h file

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ActorA.generated.h"

UCLASS()
class CPPHTTP_API AActorA : public AActor
{
	GENERATED_BODY()
	
public:	

	AActorA();

protected:

	virtual void BeginPlay() override;

public:	

	virtual void Tick(float DeltaTime) override;

	UFUNCTION()
		void sendStr();
	UFUNCTION()
		void getStr();
	UFUNCTION()
		void OnRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
	
	
};

.cpp file

#include "ActorA.h"
#include "Http.h"
#include ".h"
#include "Engine/Engine.h"

AActorA::AActorA()
{
}

void AActorA::sendStr()
{
	FHttpModule* Http = &FHttpModule::Get();
	TSharedRef<IHttpRequest> HttpRequest = Http->CreateRequest();
	HttpRequest->SetVerb("POST");
	HttpRequest->SetHeader("Content-Type", "text/plain");
	HttpRequest->SetURL("localhost:8080/a");
	HttpRequest->SetContentAsString("POST string from UE4");
	HttpRequest->ProcessRequest();
}

void AActorA::getStr()
{
	FHttpModule* Http = &FHttpModule::Get();
	TSharedRef<IHttpRequest> HttpRequest = Http->CreateRequest();
	HttpRequest->SetVerb("POST");
	HttpRequest->SetURL("localhost:8080/b");
	HttpRequest->OnProcessRequestComplete().BindUObject(this, &AActorA::OnRequestComplete);
	HttpRequest->ProcessRequest();
}

void AActorA::OnRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
	if (bWasSuccessful && Response->GetContentType() == TEXT("text/plain"))
	{
		FString result = Response->GetContentAsString();

		GEngine->AddOnScreenDebugMessage(0, 4.0f, FColor::Orange, TEXT("%s"), *result);
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(0, 4.0f, FColor::Emerald, TEXT("The Message Wanst receibed"));
	}
}


void AActorA::BeginPlay()
{
	Super::BeginPlay();

	sendStr();
	
}

void AActorA::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

.Build.cs file

using UnrealBuildTool;

public class CPPhttp : ModuleRules
{
	public CPPhttp(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
	
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Http", "", "JsonUtilities" });

		PrivateDependencyModuleNames.AddRange(new string[] {  });

		// Uncomment if you are using Slate UI
		// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
		
		// Uncomment if you are using online features
		// PrivateDependencyModuleNames.Add("OnlineSubsystem");

		// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
	}
}

If I only write the code for sendStr() it works, but if I don’t comment out the other functions It doesn’t let me compile.
I have readen a lot of examples and I haven’t seen this problem.

In cpp try including “Interfaces/IHttpRequest.h”

In *.h try removing UFUNCTION() as engine reflection system don’t support types you using in the function. If oyu not plan to use those in delegat

Thanks for the answer . I have tried that after reading your answer but Visual Studio keeps without letting me compile

Can you show me output insted of VS error tab?

You still having the unknow type errors in header file, ok revert the change (try UFUNCTION again) but in begining of headef file place:
class FHttpRequestPtr; class FHttpResponcePtr;

If you still gonna have “needs to be USTRUCT…” error remove UFUNCTION from function and try using BindRaw on delegate insted then

Using the delegate it works with BindLambda and BindStatic

But you event function is not static so how does it work? :stuck_out_tongue: you probably have null this in it if it really works

BINDLAMBDA

BINDSTATIC

Informatic things. This is a headache

Server Code

UE4 Output