//ERROR
LogHttp: Warning: 00000176BB221600: request failed, libcurl error: 1 (Unsupported protocol)
LogHttp: Warning: 00000176BB221600: libcurl info message cache 0 (Protocol "http " not supported or disabled in libcurl)
LogHttp: Warning: 00000176BB221600: libcurl info message cache 1 (Closing connection -1)
LogTemp: Warning: This is not valid
//My LoginComponentClass
// Fill out your copyright notice in the Description page of Project Settings.
#include "LoginComponent.h"
// Sets default values for this component's properties
ULoginComponent::ULoginComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
}
void ULoginComponent::BeginPlay()
{
Super::BeginPlay();
}
void ULoginComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
OnLoginResponse.Clear();
}
void ULoginComponent::Login(FString Username, FString Password)
{
//if (OnLoginResponse.IsBound()) {
// UE_LOG(LogTemp, Warning, TEXT("it is bound."))
// return;
//}
TSharedRef<IHttpRequest> request= (&FHttpModule::Get())->CreateRequest();
FString additionalString = "Username=" + Username + "&Password=" + Password;
request->SetURL(baseURL+additionalString);
UE_LOG(LogTemp, Warning, TEXT("Your message: %s"),*request.Get().GetURL());
request->SetVerb("POST");
request->OnProcessRequestComplete().BindUObject(this, &ULoginComponent::ResponseRecived);
request->ProcessRequest();
}
void ULoginComponent::ResponseRecived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (!bWasSuccessful ||!Response.IsValid()) {
UE_LOG(LogTemp, Warning, TEXT("This is not valid"));//This keeps on firing
OnLoginResponse.Clear();
return;
}
if (!EHttpResponseCodes::IsOk(Response->GetResponseCode())) {
UE_LOG(LogTemp, Warning, TEXT("Http Response returned error code: %d"), Response->GetResponseCode());
OnLoginResponse.Clear();
return;
}
OnLoginResponse.Broadcast(Response->GetContentAsString());
UE_LOG(LogTemp, Warning, TEXT("Something was returned from the response."));
OnLoginResponse.Clear();
}
___________________________________________________________________________________
My logincomponent header
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Runtime/Online/HTTP/Public/Http.h"
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "LoginComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLoginResponse, FString, ResponseString);
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class BATTLETANK_API ULoginComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
ULoginComponent();
UPROPERTY(BlueprintAssignable, Category = "Login")
FLoginResponse OnLoginResponse;
FHttpModule* Http;
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(BlueprintCallable)
void Login(FString Username,FString Password);
void ResponseRecived(FHttpRequestPtr, FHttpResponsePtr , bool );
private:
UPROPERTY(EditAnywhere, Category = "Login")
FString baseURL = TEXT("http ://localhost:8080/login?");
};