UE crashes after Json request

Hello

I have a problem: when I’m trying to execute JSON request, UE4 editor crashes with this errors in log file:

[2016.07.01-11.44.16:845][166]LogWindows:Error: === Critical error: ===
Assertion failed: IsValid() [File:D:\EGL\Epic Games\4.11\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 739]
[2016.07.01-11.44.16:893][166]LogExit: Executing StaticShutdownAfterError

Here’s the sources of executed methods:

void ALabyrinthCharacter::SendMessageToServer() {


	TSharedPtr<FJsonObject> JsonObject;
	JsonObject->SetStringField(TEXT("data"), *FString::Printf(TEXT("%s"), "Test data"));
	FString OutputString;
	TSharedRef<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<>::Create(&OutputString);
	FJsonSerializer::Serialize(JsonObject.ToSharedRef(), JsonWriter);

	TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetVerb("POST");
	HttpRequest->SetHeader("Content-Type", "application/json");
	HttpRequest->SetURL(*FString::Printf(TEXT("%s"), "http://localhost:8080/unreal/persist"));
	HttpRequest->SetContentAsString(OutputString);
	HttpRequest->OnProcessRequestComplete().BindUObject(this, &ALabyrinthCharacter::OnResponseReceived);
	HttpRequest->ProcessRequest();

}

/*Assigned function on successfull http call*/
void ALabyrinthCharacter::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{

	if (bWasSuccessful && Response->GetContentType() == "application/json")
	{
		//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))
		{
			FString result = JsonObject->GetStringField("result");
		}
	}
	else
	{
		// Handle error here
	}

	
}

How can I solve it?

It seems that I found an error.

Instead TSharedPtr JsonObject;
I should write TSharedPtr JsonObject = MakeShareable(new FJsonObject);

Now I can send JSON request, however server isn’t receiving it. But this is another story…

Hello,
I have the same problem.
The page is called on the server, but nothing in the POST.
Did you find the reason ?

D.