x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Jan 28 '15 at 01:09 PM in C++ Programming

avatar image

Shepherd
18 3 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jan 28 '15 at 02:51 PM

avatar image

trutty
541 29 32 181

avatar image Shepherd Jan 28 '15 at 03:22 PM

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.

avatar image trutty Jan 28 '15 at 03:26 PM

sry, I meant

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

does this work?

avatar image Shepherd Jan 28 '15 at 04:01 PM

Thanks Trutty!

Got it working :-)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question