Localhost Not Serving

Hello!

The game runs great until it gets to the point where I submit my score to a leaderboard, thats when the HTML5LaunchHelper.exe displays the ‘Not Serving’ message and the score never gets submitted.

The score is submitted using the HTTP Post request below:

.h

#pragma once

#include "GameFramework/Actor.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HttpRequest.generated.h"

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class BLINDSCOMGAME_API UHttpRequest : public UActorComponent
{
	GENERATED_BODY()
	
public:	
	FHttpModule* Http;

	//UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Custom)
	//FString URLName;

	// The actual HTTP call
	UFUNCTION(BlueprintCallable, Category=Custom)
	void MyHttpCall(FString URLName);

	// Assign this function to call when the GET request processes sucessfully
	void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);

	// Set Default Values for this Actor's properties
	UHttpRequest(const class FObjectInitializer& ObjectInitializer);

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
};

.cpp

#include "Game.h"
#include "HttpRequest.h"


// Sets default values
UHttpRequest::UHttpRequest(const class FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// When the object is constructed, get the HTTP module
	Http = &FHttpModule::Get();
}

// Called when the game starts or when spawned
void UHttpRequest::BeginPlay()
{
	Super::BeginPlay();
}

// HTTP CALL
void UHttpRequest::MyHttpCall(FString URLName)
{
	TSharedRef<IHttpRequest> Request = Http->CreateRequest();
	Request->OnProcessRequestComplete().BindUObject(this, &UHttpRequest::OnResponseReceived);
	Request->SetURL(URLName);
	Request->SetVerb("POST");
	//Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
	//Request->SetHeader("Content-Type", TEXT("application/json"));
	Request->ProcessRequest();
}

//Assigned function on successfull http call
void UHttpRequest::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
	//Create a pointer to hold the json serialized data
	TSharedPtr<FJsonObject> JsonObject;

	//Create a reader pointer to read the json data
	TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());

	//Deserialize the json data given reader and the actual object to deserialize

	if (FJsonSerializer::Deserialize(Reader, JsonObject))
	{
		//Get the value of the json object by field name
		int32 recievedInt = JsonObject->GetIntegerField("seconds");

		//Output it to the engine
		GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, FString::FromInt(recievedInt));
	}
}

Anyone else experience this problem or something similar? I’ve got no idea what is causing the host not to serve the URL

Any and all ideas are welcome!

hello haxo

the URL you are accessing is external to the “original” host (local or webhosted – doesn’t matter) – the URL you’ve passed in is “relative” to the “original” host.

for example, you are using URL: “dreamlo.com/lb/secret-key/add/bla/bla/bla…”

this is NOT the same as using URL: “http://dreamlo.com/lb/secret-key/add/bla/bla/bla…”

that should fix your issue. (just in case it’s not obvious – use the 2nd URL example above – the one with the “http://” protocol in front)

Thanks for the answer Nick! That did get rid of my ‘Not Serving’ error. The score still isn’t making it onto the dreamlo leaderboard though.

I know MyHttpCall works in a PC build and in the editor. Wonder what is stopping it on HTML5.