Hello guys , I got a problem while I was trying to post a json text to a php file. The problem called like the title says.
First I added the “HTTP” to my build.cs
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class LoginTest : ModuleRules
{
public LoginTest(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HTTP" });
PrivateDependencyModuleNames.AddRange(new string[] { "HTTP" });
PrivateIncludePathModuleNames.AddRange(new string[] { "HTTP" });
}
}
And my Header .h with the functions inside. I extend the UBlueprintFunctionLibrary because I need that functions inside BPs.
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "Http.h"
#include "IHttpRequest.h"
#include "HttpWrapper.generated.h"
/**
*
*/
UCLASS()
class LOGINTEST_API UHttpWrapper : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);
UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
void createRequest();
};
And finally the CPP with the code to post something to a domain including the response:
// Fill out your copyright notice in the Description page of Project Settings.
#include "LoginTest.h"
#include "HttpWrapper.h"
#include "IHttpRequest.h"
void UHttpWrapper::createRequest()
{
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetVerb(TEXT("POST"));
Request->SetURL("http://www....");
// setcontent-type to whatever you want
Request->SetHeader("Content-Type", "application/json");
Request->SetContentAsString("...");
// bind a function which gets called when the request is completed
Request->OnProcessRequestComplete().BindUObject(this, &UHttpWrapper::completedHTTPRequest);
if (!Request->ProcessRequest())
{
// HTTP request failed
}
}
void UHttpWrapper::completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful)
{
if (!response.IsValid())
{
// no valid response
}
else if (EHttpResponseCodes::IsOk(response->GetResponseCode()))
{
// valid response
FString msg = response->GetContentAsString();
}
else
{
// HTTP request error
}
}
So Visual Studio comes up with "Unrecognized type ‘FHttpRequestPtr’ " while compiling in this function call inside the Header:
UFUNCTION(BlueprintCallable, Category = "HttpWrapper")
void completedHTTPRequest(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful);
What I am doing wrong ? Any ideas or is this a bug ?