# How to make an HTTP Request from Unreal

**URL:** <https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577>\
**Category:** Community & Industry Discussion\
**Tags:** unreal-engine\
**Created:** [April 16, 2015, 8:39am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577 "2015-04-16T08:39:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_bc73617e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bc73617e](https://forums.unrealengine.com/u/anonymous_user_bc73617e)\
**Post date:** [April 16, 2015, 8:39am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/1 "2015-04-16T08:39:34Z")

</div>

Is there an easy way to connect unreal to the internet?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_741503d3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_741503d3](https://forums.unrealengine.com/u/anonymous_user_741503d3)\
**Post date:** [April 16, 2015, 9:55am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/2 "2015-04-16T09:55:51Z")

</div>

Something like that 🙂 I don’t know what level of answer you’re expecting so if the code below is too complicated then just tell me and I’ll explain what it does.

```auto

void YourClass::YourFunction()
{
        TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

        JsonObject->SetStringField(TEXT("some_string_field"), *FString::Printf(TEXT("%s"), *SomeFStringVariable));

        FString OutputString;

        TSharedRef<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<>::Create(&OutputString);

        FJsonSerializer::Serialize(JsonObject.ToSharedRef(), JsonWriter);

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

        HttpRequest->SetVerb("POST");

        HttpRequest->SetHeader("Content-Type", "application/json");

        HttpRequest->SetURL(*FString::Printf(TEXT("%s"), *UrlAddressAsString));

        HttpRequest->SetContentAsString(OutputString);

        HttpRequest->OnProcessRequestComplete().BindUObject(this, &YourClass::OnYourFunctionCompleted);

        HttpRequest->ProcessRequest();
}

void YourClass::OnYourFunctionCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
    if (bWasSuccessful && Response->GetContentType() == "application/json")
    {
        TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

        TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(Response->GetContentAsString());

        FJsonSerializer::Deserialize(JsonReader, JsonObject);

        SomeOtherVariable = JsonObject->GetStringField("some_response_field");

    }
    else
    {
        // Handle error here
    }
}

```

---

<div class="post-metadata">

**Author:** ![qdelpeche](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/qdelpeche/32/776509_2.png) [@qdelpeche](https://forums.unrealengine.com/u/qdelpeche)\
**Post date:** [April 16, 2015, 10:05am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/3 "2015-04-16T10:05:05Z")

</div>

You can also look at the Rest plugin for Unreal … depending on what you want to do.

Your post is a bit vague … do you want to load a web-page … do you want to connect to a restful web-service … do you want to make your gun run in a web-browser.

Can you provide some more information so that we can attempt to help you.

---

<div class="post-metadata">

**Author:** ![TechLord](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/techlord/32/1040563_2.png) [@TechLord](https://forums.unrealengine.com/u/TechLord)\
**Post date:** [April 16, 2015, 10:58am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/5 "2015-04-16T10:58:33Z")

</div>

[JSON Query](https://forums.unrealengine.com/showthread.php?7045-PLUGIN-JSON-Query&highlight=JSON+QUERY) works very well over HTTP/HTTPS with straight forward GET/POST Methods and full JSON Support.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41dc327b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41dc327b1](https://forums.unrealengine.com/u/anonymous_user_41dc327b1)\
**Post date:** [April 4, 2016, 12:48pm UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/6 "2016-04-04T12:48:11Z")

</div>

> [@IanBreeg;272981](#):
>
> …
> 
> void YourClass::OnYourFunctionCompleted(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)  
> {  
> if (bWasSuccessful && Response-\>GetContentType() == “application/json”)  
> {  
> TSharedPtr\<FJsonObject\> JsonObject = MakeShareable(new FJsonObject());
> 
> ```
> TSharedRef&lt;TJsonReader&lt;TCHAR&gt;&gt; JsonReader = TJsonReaderFactory&lt;TCHAR&gt;::Create(Response-&gt;GetContentAsString());
> 
> ```
> 
> …
> 
> ```auto
> 
> ```

Hi, sorry to rake up this almost a year old conversation, but I could find the solution nowhere. I tried to use the code you suggested, but I keep getting an error on the Response variable:

```auto

FHttpResponsePtr Response
Error: pointer to incomplete class type is not allowed

```

Any idea why? Of course I’m pretty new to C++ coding.

---

<div class="post-metadata">

**Author:** ![Invius](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Invius](https://forums.unrealengine.com/u/Invius)\
**Post date:** [January 23, 2019, 4:46pm UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/7 "2019-01-23T16:46:33Z")

</div>

Is there any website where i can test POST? Just to see if it catches the content that i send via json.  
I’ve been testing GET with this site: [https://pokeapi.co](https://pokeapi.co)

---

<div class="post-metadata">

**Author:** ![TScrypter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TScrypter](https://forums.unrealengine.com/u/TScrypter)\
**Post date:** [December 3, 2020, 3:25am UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/8 "2020-12-03T03:25:06Z")

</div>

> [@anonymous\_user\_41dc327b1](#):
>
> Hi, sorry to rake up this almost a year old conversation, but I could find the solution nowhere. I tried to use the code you suggested, but I keep getting an error on the Response variable:
> 
> ```auto
> 
> FHttpResponsePtr Response
> Error: pointer to incomplete class type is not allowed
> 
> ```
> 
> Any idea why? Of course I’m pretty new to C++ coding.

I realize it’s been a while since the question, but when an error of “\* to incomplete class type is not allowed” is usually an issue with the file you’re working in (most likely the .cpp if you’re implementing) doesn’t have an include line for the header file where the type is defined. So for this specific issue, you would want to add to the include section of your file

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Rasie1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rasie1/32/88710_2.png) [@Rasie1](https://forums.unrealengine.com/u/Rasie1)\
**Post date:** [April 15, 2022, 7:02pm UTC](https://forums.unrealengine.com/t/how-to-make-an-http-request-from-unreal/27577/9 "2022-04-15T19:02:07Z")

</div>

If someone googles through this thread (it’s the first result) and just wants to copy paste a quick http request without butchering your code with all of that above, here it is:

```auto
    auto request = FHttpModule::Get().CreateRequest();
    request->SetURL(FString("http://google.com"));
    request->OnProcessRequestComplete().BindLambda([](FHttpRequestPtr request, FHttpResponsePtr response, bool success) {
    });
    request->ProcessRequest();

```
