Request->OnProcessRequestComplete() gets called only on first play session

I have been trying to fix this for a while, but to no success, which is why I have come to here to hopefully get an answer to what is going wrong. I am writing a little tool so our team can submit bugs to Trello through the game itself. I have set this up and it sort of works, sort of meaning it only works on the first play session after opening the engine, all the following play sessions will work only partly.

It works perfectly during the first play session (but only in engine, not in a packaged build). Every following session, nothing seems to be called after Request.OnProcessRequestComplete() for whatever reason and I cannot figure out why. All of this is located inside of a singleton class for blueprint utilities.

Here is the code that is responsible for this

void UHttpUtilities::SubmitCardToTrello(const FString& CardName, const FString& CardDescription, const TArray<FString>& CardLabels, const FString& ImageFilePath)
{
	ImagePath = ImageFilePath;
	
	FHttpModule* Http = &FHttpModule::Get();
	TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = Http->CreateRequest();

	FString LabelIDString;
	for (const FString& Label : CardLabels)
	{
		LabelIDString += FString::Printf(TEXT("\"%s\", "), *Label);
	}

	if(LabelIDString.Len() > 0)
	{
		LabelIDString.RemoveAt(LabelIDString.Len() - 2, 2);
	}

	LabelIDString = FString::Printf(TEXT("[%s]"), *LabelIDString);

	const FString URL = FString::Printf(TEXT("https://api.trello.com/1/cards?idList=%s&key=%s&token=%s"), *CardListID, *APIKey, *APIToken);

	Request->SetURL(URL);
	Request->SetVerb("POST");

	Request->SetHeader("Content-Type", "application/json");
	Request->SetHeader("Cache-Control", "no-cache");
	Request->SetHeader("Pragma", "no-cache");

	//Create request body
	FString RequestBody = FString::Printf(TEXT(
			"{ \"name\": \"%s\", \"desc\": \"%s\", \"idList\": \"%s\", \"key\": \"%s\", \"token\": \"%s\", \"idLabels\": %s }"),
			*CardName, *CardDescription, *CardListID, *APIKey, *APIToken, *LabelIDString);

	Request->SetContentAsString(RequestBody);
	
	Request->OnProcessRequestComplete().BindUObject(this, &UHttpUtilities::OnResponseReceived);

	if(Request->ProcessRequest())
	{
		UE_LOG(LogTemp, Warning, TEXT("Trello request sent successfully."));
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("Failed to send Trello request!"));
	}
}

If anyone has any clue, I would much appreciate it!

A bit of an update on this. I have confirmed that I am not getting a response back from Trello on every play session besides that first one where everything works perfectly. I have doubts that the issue is on Trello’s side however, it’s much more likely either I am doing something wrong or something funky is happening in Unreal’s background somehow.

Another update. The issue also exists when you change from one level to another. I thought maybe it had to do with it being derived from a UObject so instead I made it a child of UUserWidget, this just gives me the exact same result however. The request times out without giving me a response back, but the cards are still being created in Trello.

Perhaps try increasing the timeout period in the request via IHttpRequest

The server processing your request might have you as low priority so you may not be getting responses in the needed time window.

Try looking into an external tool to monitor network traffic. Perhaps looking into the transport of the data itself might let you know where the communication fails.

Something like Wireshark might do the job.

I had already increased the timeout to 60 seconds and that unfortunately did not do anything.

However, I kind of fixed it, but not in a way that should be used to fix it I am fairly certain. What I ended up doing is forcably flush the request a bit after it has been sent, meaning it is forced to complete the request (At least I think so) After doing that it seems to work perfectly now, however I am aware that if we will do anything else related to Http requests, it might ■■■■ it up in some way, but that might just be an issue for later.

You could move the http request handling to a singleton subsystem based on gameInstance. You would have only one instance then and you wouldn’t run into calling 2 requests simultaneously if that is what you need.

I’ve actually done this as well, it was a singleton class I made for http utilities in blueprints, what I’ve ended up with is just making it a UUserWidget derived class, that however was not the thing that fixed it, only the flushing seems to have worked after trying an incredible amount of things to fix it.

You could add the flush command within the function bound to the rquestcomplete delegate function. It would then trigger at the correct time.(you might already have this)

Or as a cleanup function that is triggered if it fails or succeeds.

Also have you seen this thread regarding ssl?

It also tackles a lack if response but it due to certificates.