void ATestProjectGameModeBase::HttpCall(const FString& InURL, const FString& InVerb)
{
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &ATestProjectGameModeBase::OnResponseReceived);
//This is the url on which to process the request
Request->SetURL(InURL);
Request->SetVerb(InVerb);
Request->SetHeader("Content-Type", TEXT("application/json"));
TSharedRef<FJsonObject> RequestObj = MakeShared<FJsonObject>();
RequestObj->SetStringField("input", "obj");
RequestObj->SetStringField("voice", "obj");
FString RequestBody;
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&RequestBody);
FJsonSerializer::Serialize(RequestObj, Writer);
Request->SetContentAsString(RequestBody);
Request->ProcessRequest();
UE_LOG(LogTemp, Warning, TEXT("HttpCall url : %s\nrequestBody : %s"), *InURL, *RequestBody);
}
void ATestProjectGameModeBase::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("OnResponseReceived url : %s\nrecv : %s"), *Request->GetURL(), *Response->GetContentAsString());
//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("customInt");
UE_LOG(LogTemp, Warning, TEXT("HTTP request result customInt : %d"), recievedInt);
}
}
OnResponseReceived ํจ์๋ ์๋์ํ๋๊ฒ ์ ์์ธ๊ฑฐ์ผ??
์ ์ด์จ ํ์๊ด๋ จ ์์ ๋ค ๋ค ์ฝ๋ฐฑ์ผ๋ก ํด๋ง๋๋ฐ ๋ฆฌ์คํฐ๊ฐ ๋ค ์๋ฐ์์ง๋ค ใ
ใ
์ข๋์์ค
๋๊ธ 0