Unrecognized type 'FHttpRequestPtr'

Hello guys , I got a problem while I was trying to post a json text to a php file. The problem called like the title says.
First I added the “HTTP” to my build.cs


// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class LoginTest : ModuleRules
{
	public LoginTest(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HTTP" });
        PrivateDependencyModuleNames.AddRange(new string[] { "HTTP" });
        PrivateIncludePathModuleNames.AddRange(new string[] { "HTTP" });
	}
}

And my Header .h with the functions inside. I extend the UBlueprintFunctionLibrary because I need that functions inside BPs.


#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "Http.h" 
#include "IHttpRequest.h"
#include "HttpWrapper.generated.h"

/**
 * 
 */

UCLASS()
class LOGINTEST_API UHttpWrapper : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()
			

	UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
	 void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);
	

	UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
		void createRequest();
	
	
};

And finally the CPP with the code to post something to a domain including the response:


// Fill out your copyright notice in the Description page of Project Settings.

#include "LoginTest.h"
#include "HttpWrapper.h"
#include "IHttpRequest.h"




void UHttpWrapper::createRequest()
{
	TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
	Request->SetVerb(TEXT("POST"));
	Request->SetURL("http://www....");
	// setcontent-type to whatever you want
	Request->SetHeader("Content-Type", "application/json");
	Request->SetContentAsString("...");
	
		// bind a function which gets called when the request is completed
	Request->OnProcessRequestComplete().BindUObject(this, &UHttpWrapper::completedHTTPRequest);
	
	if (!Request->ProcessRequest())
	{
		// HTTP request failed
	}
}

void UHttpWrapper::completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful)
{
	if (!response.IsValid())
	{
		// no valid response
	}
	else if (EHttpResponseCodes::IsOk(response->GetResponseCode()))
	{
		// valid response
		FString msg = response->GetContentAsString();
	}
	else
	{
		// HTTP request error
	}
}

So Visual Studio comes up with "Unrecognized type ‘FHttpRequestPtr’ " while compiling in this function call inside the Header:


UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
	 void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);

What I am doing wrong ? Any ideas or is this a bug ?

FHttpRequestPtr and FHttpResponsePtr are a typedefs, and unfortunately, UHT (which is what’s generating that error) doesn’t understand typedefs.

You could try using their expanded forms for your UFUNCTION and see if that works:

typedef TSharedPtr<class IHttpRequest> FHttpRequestPtr;
typedef TSharedPtr<class IHttpResponse,ESPMode::ThreadSafe> FHttpResponsePtr;

EDIT: Although that won’t work either as neither IHttpRequest nor IHttpResponse are UObject based types, so can’t be used as parameters to a UFUNCTION. You could maybe try making a UObject based wrapper object (if we don’t have one of those already) if you really need to use them within the UObject system.

You can remove the “HTTP” from line 10 in your *.build.cs. In your header file you can remove the lines 5 and 6. In your cpp file you can remove line 5.
Maybe the error has something to do with those lines. The rest looks fine, as it is my working code :wink:

I did a small code cleanup like you said but didn’t help …

Thank you for posting this fast guys. After a little code cleanup I took a look into “ufna’s” VaRest source and noticed the he isn’t using “UFUNCTION” for this:


UCLASS(BlueprintType, Blueprintable)
class UVaRestRequestJSON : public UObject
{
GENERATED_UCLASS_BODY()

// Request callbacks
private:
...
/** Internal bind function for the IHTTPRequest::OnProcessRequestCompleted() event */
void OnProcessRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
...
};

So I did this the same way:


UCLASS(BlueprintType, Blueprintable)
class HTTPTEST_API UHttpWrapper : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

private:
	//UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
	void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);

public:
	//UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
		void createRequest();
	
	
};

Well now it compiles more then before but I got a LNK2019 (unresolved external symbol)

1 Like

Hmm your createRequest() function can has a UFUNCTION macro. A UFUNCTION(BlueprintCallable, ...) macro for the completedHTTPRequest function is pointless because you will never call it from a Blueprint (did not notice this before).

Why did you change class LOGINTEST_API UHttpWrapper : public UBlueprintFunctionLibrary to class HTTPTEST_API UHttpWrapper : public UBlueprintFunctionLibrary in your header file? Please try your old, code cleaned, code but remove the UFUNCTION macro for the completedHTTPRequest function. Sry I can’t test your code right now so I am just trying some stuff…


error LNK2019: unresolved external symbol""public: __cdecl UHttpWrapper::UHttpWrapper(class FObjectInitializer const &)" (??0UHttpWrapper@@QEAA@AEBVFObjectInitializer@@@Z)" in Funktion ""public: static void __cdecl UHttpWrapper::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@UHttpWrapper@@SAXAEBVFObjectInitializer@@@Z)".	C:\Users\Roman\Documents\Unreal Projects\Httptest\Intermediate\ProjectFiles\HttpWrapper.cpp.obj	Httptest

and


error LNK2001:  ""public: __cdecl UHttpWrapper::UHttpWrapper(class FObjectInitializer const &)" (??0UHttpWrapper@@QEAA@AEBVFObjectInitializer@@@Z)".	C:\Users\Roman\Documents\Unreal Projects\Httptest\Intermediate\ProjectFiles\Httptest.generated.cpp.obj	Httptest

I am about to give up soon :frowning: . I am also very new to C++ and came from C#…

:slight_smile: , Mate the Ufunctions are commented out with “//”, well , here is the whole source again in the answer below this because of the code highlighting.

The new httpwrapper.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "Httptest.h"
#include "HttpWrapper.h"

void UHttpWrapper::createRequest()
{
	TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
	Request->SetVerb(TEXT("POST"));
	Request->SetURL("http://www....");
	// setcontent-type to whatever you want
	Request->SetHeader("Content-Type", "application/json");
	Request->SetContentAsString("...");

	// bind a function which gets called when the request is completed
	Request->OnProcessRequestComplete().BindUObject(this, &UHttpWrapper::completedHTTPRequest);

	if (!Request->ProcessRequest())
	{
		// HTTP request failed
	}
}

void UHttpWrapper::completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful)
{
	if (!response.IsValid())
	{
		// no valid response
	}
	else if (EHttpResponseCodes::IsOk(response->GetResponseCode()))
	{
		// valid response
		FString msg = response->GetContentAsString();
	}
	else
	{
		// HTTP request error
	}
}

The new httpwrapper.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Http.h"
#include "HttpWrapper.generated.h"


/**
 * 
 */
UCLASS(BlueprintType, Blueprintable)
class HTTPTEST_API UHttpWrapper : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

private:
	
	void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);

public:
	
		void createRequest();
	
	
};

and finally the build.cs


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class Httptest : ModuleRules
{
	public Httptest(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HTTP" });
        
	}
}

and this brings me:

 error LNK2019: unresolved external symbol""public: __cdecl UHttpWrapper::UHttpWrapper(class FObjectInitializer const &)" (??0UHttpWrapper@@QEAA@AEBVFObjectInitializer@@@Z)" in Funktion ""public: static void __cdecl UHttpWrapper::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@UHttpWrapper@@SAXAEBVFObjectInitializer@@@Z)".    C:\Users\Roman\Documents\Unreal Projects\Httptest\Intermediate\ProjectFiles\HttpWrapper.cpp.obj    Httptest


and

 error LNK2001:  ""public: __cdecl UHttpWrapper::UHttpWrapper(class FObjectInitializer const &)" (??0UHttpWrapper@@QEAA@AEBVFObjectInitializer@@@Z)".    C:\Users\Roman\Documents\Unreal Projects\Httptest\Intermediate\ProjectFiles\Httptest.generated.cpp.obj    Httptest

GENERATED_UCLASS_BODY() requires you to define a UHttpWrapper::UHttpWrapper(const FObjectInitializer&) function in your cpp file.

You can either do that, or you can just use GENERATED_BODY() instead, as that doesn’t require you to define that function yourself.

Well its working, thank you really much, I will release a tutorial about this these days.