I don’t know what I need to add to my new code because I don’t know how to get MessageBody in a node, I’m using delegates but it’s difficult to understand it and the code which you can find below has errors and I don’t know why.
Could you tell me how would be the code?
.H:
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HttpConnections.generated.h"
DECLARE_DYNAMIC_DELEGATE(Delegate, FString, Messagebody);
UCLASS()
class PROYECTOIMAG_API UHttpConnections : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
FHttpModule* Http;
UFUNCTION(BlueprintCallable, Category = "Arch Function")
static void MyHttpCall();
UPROPERTY(BlueprintReadWrite, Category = "Delegate", VisibleAnywhere)
Delegate Resultado;
void RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
public:
UFUNCTION(BlueprintPure)
void Retrieve(Delegate& Messagebody);
};
.cpp:
#include "ProyectoImag.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "Engine.h"
#include "HttpConnections.h"
/*Http call*/
void UHttpConnections::MyHttpCall()
{
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
/*This is the url on which to process the request*/
//Get a la base de datos
Request->SetVerb("GET");
Request->SetHeader("Content-Type", TEXT("application/"));
Request->SetURL("http://localhost/basic/web/index.php?r=objetos%2Frecoger");
Request->OnProcessRequestComplete().BindUObject(this, &UHttpConnections::RequestComplete);
Request->ProcessRequest();
}
void UHttpConnections::RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
FString Messagebody;
Messagebody=Response->GetContentAsString();
Resultado.Broadcast(Messagebody);
}
void UHttpConnections::Retrieve(const ResultadoDelegate& Messagebody)
{
Resultado = Messagebody;
}
Thanks.