Hello everybody!
**my tutorial follow other that describe how to do web requests and compute the messages using UE4 HTTP and JSON modules, please look to the following reference materiels first
after reading the materiels here you should be ready to do a web request and use the message back in your game
- go to make the new project, basic code, mine is named tutorial
**
**
2. go to tutorial.Build.cs and make it from this
**
**
into this
**
**
3. make tutorial.h to be like this
**
**
4. do not make tutorial.cpp to be different!!
5. make your blueprint in UE4 like this C++ Classes>Right Click>New C++ Class>Actor, mine is named test
7. compile to test and see if no bugs, if there are bugs check materiels in beginning of this post
**8. make test.h to be like
// Fill out your copyright notice in the Description page of Project Settings.**
**#pragma once**
**#include "Engine.h"**
**#include "GameFramework/Actor.h"**
**#include "Runtime/Online/HTTP/Public/Http.h"**
**#include "JsonObjectConverter.h"**
**#include "test.generated.h"**
**USTRUCT(BlueprintType)**
**struct FEstados**
**{**
**GENERATED_BODY()**
**UPROPERTY(BlueprintReadOnly)**
**FString id;**
**UPROPERTY(BlueprintReadOnly)**
**FString key;**
**UPROPERTY(BlueprintReadOnly)**
**FString name;**
**UPROPERTY(BlueprintReadOnly)**
**FString shortname;**
**FEstados()**
**{**
**id = "";**
**key = "";**
**name = "";**
**shortname = "";**
**}**
**};**
**USTRUCT(BlueprintType)**
**struct FMessage**
**{**
**GENERATED_BODY()**
**UPROPERTY(BlueprintReadOnly)**
**TArray<FEstados> states;**
**FMessage()**
**{**
**}**
**};**
**DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMessageBack, FMessage, messageResponse);**
**UCLASS()**
**class TUTORIAL_API Atest : public AActor**
**{**
**GENERATED_BODY()**
**public:**
**// Sets default values for this actor's properties**
**Atest();**
**FHttpModule* Http;**
**UPROPERTY(BlueprintAssignable)**
**FMessageBack Message;**
**UFUNCTION(BlueprintCallable, meta = (DisplayName = "test", CompactNodeTitle = "test", Keywords = "test"), Category = test)**
**void Test();**
**void TestMessage(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);**
**protected:**
**// Called when the game starts or when spawned**
**virtual void BeginPlay() override;**
**public:**
**// Called every frame**
**virtual void Tick(float DeltaTime) override;**
**};**
9. make test.cpp to be like
**// Fill out your copyright notice in the Description page of Project Settings.**
**#include "Public/test.h"**
**#include "tutorial.h"**
**// Sets default values**
**Atest::Atest()**
**{**
**// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.**
**PrimaryActorTick.bCanEverTick = true;**
**Http = &FHttpModule::Get();**
**}**
**// Called when the game starts or when spawned**
**void Atest::BeginPlay()**
**{**
**Super::BeginPlay();**
**}**
**// Called every frame**
**void Atest::Tick(float DeltaTime)**
**{**
**Super::Tick(DeltaTime);**
**}**
**void Atest::Test()**
**{**
**TSharedRef<IHttpRequest> Request = Http->CreateRequest();**
**Request->OnProcessRequestComplete().BindUObject(this, &Atest::TestMessage);**
**Request->SetURL("https://raw.githubusercontent.com/dantaex/ciudades_mexico/master/states_mexico.json");**
**Request->SetVerb("GET");**
**Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");**
**Request->SetHeader("Content-Type", TEXT("application/json"));**
**Request->ProcessRequest();**
**}**
**void Atest::TestMessage(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)**
**{**
**TSharedPtr<FJsonObject> JsonObject;**
**TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());**
**if (FJsonSerializer::Deserialize(Reader, JsonObject))**
**{**
**FMessage message;**
**FJsonObjectConverter::JsonObjectStringToUStruct(Response->GetContentAsString(), &message, 0, 0);**
**Message.Broadcast(message);**
**}**
**}**
10. build again, now actor is ready to use!! Put into scene
**
**
11. then use in blueprint like
**
**
OUTPUT
**LogBlueprintUserMessages: [test_C_17] 0, Todo México**
**LogBlueprintUserMessages: [test_C_17] 1, Aguascalientes**
**LogBlueprintUserMessages: [test_C_17] 2, Baja California**
**LogBlueprintUserMessages: [test_C_17] 3, Baja California Sur**
**LogBlueprintUserMessages: [test_C_17] 4, Campeche**
**LogBlueprintUserMessages: [test_C_17] 5, Coahuila de Zaragoza**
**LogBlueprintUserMessages: [test_C_17] 6, Colima**
**LogBlueprintUserMessages: [test_C_17] 7, Chiapas**
**LogBlueprintUserMessages: [test_C_17] 8, Chihuahua**
**LogBlueprintUserMessages: [test_C_17] 9, Distrito Federal**
**LogBlueprintUserMessages: [test_C_17] 10, Durango**
**LogBlueprintUserMessages: [test_C_17] 11, Guanajuato**
**LogBlueprintUserMessages: [test_C_17] 12, Guerrero**
**LogBlueprintUserMessages: [test_C_17] 13, Hidalgo**
**LogBlueprintUserMessages: [test_C_17] 14, Jalisco**
**LogBlueprintUserMessages: [test_C_17] 15, México**
**LogBlueprintUserMessages: [test_C_17] 16, Michoacán de Ocampo**
**LogBlueprintUserMessages: [test_C_17] 17, Morelos**
**LogBlueprintUserMessages: [test_C_17] 18, Nayarit**
**LogBlueprintUserMessages: [test_C_17] 19, Nuevo León**
**LogBlueprintUserMessages: [test_C_17] 20, Oaxaca**
**LogBlueprintUserMessages: [test_C_17] 21, Puebla**
**LogBlueprintUserMessages: [test_C_17] 22, Querétaro**
**LogBlueprintUserMessages: [test_C_17] 23, Quintana Roo**
**LogBlueprintUserMessages: [test_C_17] 24, San Luis Potosí**
**LogBlueprintUserMessages: [test_C_17] 25, Sinaloa**
**LogBlueprintUserMessages: [test_C_17] 26, Sonora**
**LogBlueprintUserMessages: [test_C_17] 27, Tabasco**
**LogBlueprintUserMessages: [test_C_17] 28, Tamaulipas**
**LogBlueprintUserMessages: [test_C_17] 29, Tlaxcala**
**LogBlueprintUserMessages: [test_C_17] 30, Veracruz de Ignacio de la Llave**
**LogBlueprintUserMessages: [test_C_17] 31, Yucatán**
**LogBlueprintUserMessages: [test_C_17] 32, Zacatecas**
IT WORKS!
Thank you and I hope you can understand, this taken me a long time to find out and really is helping in my game hope you can ask any questions here