FHttpModule Usage Issues

Hey All,

I have done the following:

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

using UnrealBuildTool;

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

and in my wrapper header I have:

#include "Runtime/Online/HTTP/Public/Http.h"

However when attempting to use the following code:

TSharedRef<IHttpRequest> Request = (&FHttpModule::Get())->CreateRequest();

Visual studio is complaining about Get(); not being a member of FHttpModule…

I am coming from C# so I might be doing something wrong here as my C++ is a bit basic to say the least.

Is it possible for any of you to maybe help me out? I am using 4.6.1 and need to do some login code for my game that requires an http connection to my server.

Use

TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
instead.
VS is complaining at my side too, however it works anyway and also should regarding too the docs (FHTTPModule).

After that, you have to make your GET or POST request. Check out IHttpRequest for more info.

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, &Sandbox::completedHTTPRequest);
...
if (!Request->ProcessRequest())
{
	// HTTP request failed
}

The bind function would than look something like:

void Sandbox::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
    	}
}

Hope this helps.

Hi Trutty,

Thanks for taking the time to respond to my problem. Unfortunately this does not work for me.

using this: TSharedRef req = FHttpModule::Get().CreateRequest();
results in the following errors:

error C2955: ‘TSharedRef’ : use of class template requires template argument list

error C2514: ‘TSharedRef’ : class has no constructors

According to the intelli hints I should be doing this: TSharedRef req

however it still leaves me with the ::Get(); that is not a member of FHttpModule.

This all results in a failed build sadly.

sry, I meant

TSharedRef<IHttpRequest> req = FHttpModule::Get().CreateRequest();
. using the code tag resulted in deleting everything between “<…>”

does this work?

Thanks Trutty!

Got it working :slight_smile:

i have similar issue, the code is directly from your wiki-archive.

includes:
#include “Runtime/Online/HTTP/Public/Http.h”

line:
TSharedRef < IHttpRequest > HttpRequest = FHttpModule::Get().CreateRequest();

cause:
ompilerResultsLog: /home/nikolai/Dokumente/Unreal Projects/TP_Android_Test/Source/TP_Android_Test/BFL_ServerCom.cpp:33: undefined reference to `FHttpModule::Get()’