I'm saving the value of a token in the class variable _Token
The token is added to the request header in CreateHttpPostRequest
I make a HTTP request call in PostToJira
using CreateHttpPostRequest
, and bind the response to OnResponseReceived
.
Once i get the response, I call AddScreenshot
, where I again make a request using CreateHttpPostRequest
, and add a screenshot to the issue. (You can only add a screenshot to an existing issue, which is why we have to make it first, then add the screenshot in a subsequent call.)
The problem is the value of _Token
is empty when AddScreenshot
is called, and I don't know why.
When debugging the watch value shows this: c++ Stopped in a C++ method, but 'this' isn't available; pretending we are in a generic context. error: use of undeclared identifier '_Token'
I've tried using BindLambda instead, thinking that maybe Raw was causing the problem, but it looks like there's something about binding the function that's emptying that member variable. Even when I defined the value of _Token
in the header file in lieu of using AuthMan::GetToken(_Token)
. The value is still empty.
I also tried this->_Token
with the same result.
Here are my header and cpp files, sanitized to just show the problem and context:
HtttpUtil.h
class HttpUtil
{
public:
bool PostToJira();
private:
void AddScreenshot() const;
void OnResponseReceived(FHttpRequestPtr request, FHttpResponsePtr response, bool bConnectedSuccessfully) const;
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> CreateHttpPostRequest() const;
FString _Token = "my_token";
};
HttpUtil.cpp
bool HttpUtil::PostToJira()
{
const FHttpRequestRef request = CreateHttpPostRequest();
request->OnProcessRequestComplete().BindRaw(this, &HttpUtil::OnResponseReceived);
request->ProcessRequest();
return true;
}
void HttpUtil::AddScreenshot() const
{
const FHttpRequestRef request = CreateHttpPostRequest();
request->ProcessRequest();
}
void HttpUtil::OnResponseReceived(FHttpRequestPtr request, FHttpResponsePtr response, bool bConnectedSuccessfully) const
{
AddScreenshot();
}
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpUtil::CreateHttpPostRequest() const
{
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> request = FHttpModule::Get().CreateRequest();
request->SetURL("http://echo.jsontest.com/key/value/one/two");
// When this function is called by AddScreenshot(), the _Token value is empty
UE_LOG(LogConsoleResponse, Warning, TEXT("_Token = %s"), *_Token);
return request;
}