Syntax Error: identifier 'FHttpRequestPtr'

I cannot test http in ue4. I have read some tutorial but I cannot reimplement them.

HttpTestGameMode.h:

UCLASS()
class PROGRAMMINGTUTORIAL_API AHttpTestGameMode : public AGameMode
{
	GENERATED_BODY()

public:

	virtual void BeginPlay() override;

	void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccessful);

private:
	class FHttpModule* Http;

	void SetHttpModule();
	
};

HttpTestGameMode.cpp:

#include "Http.h"
#include "HttpModule.h"
#include "IHttpRequest.h"
#include "IHttpBase.h"
#include "IHttpResponse.h"

...
Request->OnProcessRequestComplete().BindUObject(this, &AHttpTestGameMode::OnResponseReceived);
...

void AHttpTestGameMode::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccessful)
{
//TODO IMPLEMENT LATER
}

Error Message:

HttpTestGameMode.h(20): error C2061: syntax error: identifier 'FHttpRequestPtr'
HttpTestGameMode.h(20): error C2061: syntax error: identifier 'FHttpRequestPtr'
HttpTestGameMode.cpp(20): error C2664: 'void TBaseDelegate<TTypeWrapper<void>,FHttpRequestPtr,FHttpResponsePtr,bool>::BindUObject<AHttpTestGameMode,>(UserClass *,void (__cdecl AHttpTestGameMode::* )(FHttpRequestPtr,FHttpResponsePtr,bool) const)': cannot convert argument 2 from 'void (__cdecl AHttpTestGameMode::* )(void)' to 'void (__cdecl AHttpTestGameMode::* )(FHttpRequestPtr,FHttpResponsePtr,bool)'

Build.cs:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HTTP" });

Try adding #include “Http.h” in your header file. FHttpRequestPtr and FHttpResponsePtr are type defs which are defined in IHttpRequest.h which is included in Http.h.

It might cause a problem if I include it in my header file? I was doing such trick for other classes by putting the keyword ‘class’ for classes not to include them in header but cpp file. However, because they are typedefs, I do not know what to do.

It shouldn’t cause any problems.

Adding class in front of class definitions in header files isn’t a “trick”, it is called a forward declaration. A forward declaration is simply identifying something without giving it a complete definition. If your header needed to know more details about the class, then doing a forward declaration wouldn’t work.

Typedefs are more or less a mapped identifier. That is to say, you’re saying X is Y. It is an ease of use keyword, for example instead of typing TArray all the time you can typedef it to just be MyClassPointerContainer and use that. That is what FHttpRequestPtr and FHttpResponsePtr are.

Thank you for that detailed answer :slight_smile:

For anyone else looking now, make sure you aren’t using UFUNCTION for the function. Apparently that causes issues. If anyone knows why i’d love to understand :slight_smile: