VaRest icon indicating copy to clipboard operation
VaRest copied to clipboard

How Can I use this plugin in C++ not BP

Open eusru opened this issue 2 years ago • 5 comments

Any Tips or sample ?

eusru avatar Apr 25 '22 02:04 eusru

OK.... I have solved this...

this is my sample to use VaRestSubsystem Callurl. Use UVaRestSubsystem as singleton to create RequestObject ,ResponseObject, RequestJsonObject

And another is the same as this sample.,like post a json body ,set header...and so on. .h

FVaRestCallDelegate CallDelegate;
UFUNCTION()
void CallBack(UVaRestRequestJSON* Request);

.cpp

void AJsonActor::BeginPlay()
{
	Super::BeginPlay();
	UVaRestSubsystem* VaRestSubsystem=GEngine->GetEngineSubsystem<UVaRestSubsystem>();
	auto JsonObject = VaRestSubsystem->ConstructVaRestJsonObject();
	CallDelegate.BindDynamic(this,&AJsonActor::CallBack);
	VaRestSubsystem->CallURL(TEXT("URL"),EVaRestRequestVerb::GET,EVaRestRequestContentType::x_www_form_urlencoded_url,JsonObject,CallDelegate);

}

void AJsonActor::CallBack(UVaRestRequestJSON* Request)
{
	UE_LOG(LogTemp,Warning,TEXT("Request Response is %s"),*Request->GetResponseObject()->EncodeJson());
}

eusru avatar Apr 25 '22 04:04 eusru

No this is not a good way of getting the Subsystem It should be done like this UVaRestSubsystem* VaRestSubsystem = GEngine->GetEngineSubsystem<UVaRestSubsystem>();

Maxmystere avatar Apr 25 '22 07:04 Maxmystere

No this is not a good way of getting the Subsystem It should be done like this UVaRestSubsystem* VaRestSubsystem = GEngine->GetEngineSubsystem<UVaRestSubsystem>();

AllRight... it's better!!! Thanks!

eusru avatar Apr 25 '22 07:04 eusru

I want to know the JsonObject how to pass parameters

PengChaoJay avatar May 24 '23 08:05 PengChaoJay

i get it, all my problem is done

PengChaoJay avatar May 29 '23 03:05 PengChaoJay