Hi,
I created simple class to download data from website.
This code works excellent on windows system.
HTML5 returns error that it cannot connect with given url (“localhost/software/testData”).
cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "HttpTest.h"
#include "Engine.h"
// Sets default values
AHttpTest::AHttpTest()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
UE_LOG(LogTemp, Warning, TEXT("Creating WebManager..."));
PrimaryActorTick.bCanEverTick = true;
// Get the HTTP module
m_http = &FHttpModule::Get();
m_http->SetHttpTimeout(600);
}
void AHttpTest::Destroyed()
{
UE_LOG(LogTemp, Warning, TEXT("Destroying WebManager..."));
}
// Http call
void AHttpTest::GetData()
{
TSharedRef<IHttpRequest> Request = m_http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AHttpTest::OnResponseReceived);
//Request->OnRequestProgress().BindUObject(this, &)
Request->SetURL("localhost/software/testData");
Request->SetVerb("GET");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->ProcessRequest();
}
// Assigned function on successfull http call
void AHttpTest::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Response received!"));
m_names.Empty();
m_names.Add(FString::FormatAsNumber(Request->GetStatus()));
m_listUpdated.Broadcast(m_urls, m_names);
}
Request->GetStatus() = 2, what means “Failed because it was unable to connect (safe to retry)”.
How to fix it?