Hi everyone,
I’ve been struggling for two days now trying to figure out what’s wrong with my code. I’m sending an HTTP GET request to my API, which returns a JSON string. However, I noticed something strange: even when I explicitly specify the port as 127.0.0.1:19100
, the libcurl
library in the logs keeps redirecting the request to port 12678
.
The only way my function works is if I run the API server locally on port 12678
. No other configuration seems to work.
I even tried testing this in a blank project with the HttpBlueprint plugin enabled and performed a simple GET request—same result.
Unreal Engine 5.4.1 (Git version)
Windows 10
Any ideas why this port redirection is happening?
Лог ошибки
[2025.04.30-10.06.14:536][207]LogHttp: Warning: 00000BBAD77EA800: request failed, libcurl error: 7 (Couldn't connect to server)
[2025.04.30-10.06.14:536][207]LogHttp: Warning: 00000BBAD77EA800: libcurl info message cache 0 (Hostname 127.0.0.1 was found in DNS cache)
[2025.04.30-10.06.14:536][207]LogHttp: Warning: 00000BBAD77EA800: libcurl info message cache 1 ( Trying 127.0.0.1:12678...)
[2025.04.30-10.06.14:536][207]LogHttp: Warning: 00000BBAD77EA800: libcurl info message cache 2 (connect to 127.0.0.1 port 12678 failed: Connection refused)
[2025.04.30-10.06.14:536][207]LogHttp: Warning: 00000BBAD77EA800: libcurl info message cache 3 (Failed to connect to 127.0.0.1 port 12678 after 2021 ms: Couldn't connect to
void AAPI_get_data::RequestCrystalData(const FString& crystalName)
{
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
FString Url = FString::Printf(TEXT("https://api.example.ru/client/%s/data"), *crystalName);
HttpRequest->SetURL(Url);
HttpRequest->SetHeader(TEXT("Access-Control-Allow-Origin"), TEXT("*"));
HttpRequest->SetHeader(TEXT("Access-Control-Allow-Methods"), TEXT("GET"));
HttpRequest->OnProcessRequestComplete().BindUObject(this, &AAPI_get_data::OnCrystalDataReceived);
HttpRequest->ProcessRequest();
}
void AAPI_get_data::OnCrystalDataReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (!bWasSuccessful)
{
UE_LOG(LogTemp, Error, TEXT("Connection failed. Reason: %s"));
return;
}
if (!Response.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("Invalid response"));
return;
}
UE_LOG(LogTemp, Display, TEXT("HTTP Status: %d"), Response->GetResponseCode());
UE_LOG(LogTemp, Log, TEXT("HTTP Status: %d"), Response->GetResponseCode());
if (Response->GetResponseCode() == 200)
{
JsonString = Response->GetContentAsString();
UE_LOG(LogTemp, Log, TEXT("Raw JSON: %s"), *JsonString);
responseFromNKU();
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(JsonString);
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
if (JsonObject->GetStringField("block_type").Equals(TEXT("0xCD")))
JsonString0XCD = JsonString;
if (JsonObject->GetStringField("block_type").Equals(TEXT("0x7A")))
JsonString0X7A = JsonString;
if (JsonObject->GetStringField("block_type").Equals(TEXT("0x7B")))
JsonString0X7B = JsonString;
if (JsonObject->GetStringField("block_type").Equals(TEXT("0x21")))
JsonString0X21 = JsonString;
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to parse JSON!"));
}
}
else if (Response->GetResponseCode() >= 300 && Response->GetResponseCode() < 400)
{
FString RedirectURL = Response->GetHeader("Location");
UE_LOG(LogTemp, Warning, TEXT("Redirected to: %s"), *RedirectURL);
}
else
{
UE_LOG(LogTemp, Error, TEXT("HTTP Error: %d"), Response->GetResponseCode());
}
}