Hello,
i have a project where i would send a HttpRequest if i hit the play button. It will send a message to my node.js server and this would just take the message and log it on the console. This works fine if i start it from the browser. Now i want to launch this project in Html 5 and my server does not get any data.
This is my server index.js
var http = require('http');
var postHTML =
'<html><head><title>Post Example</title></head>' +
'<body>' +
'<form method="post">' +
'Input 1: <input name="input1">
’ +
'Input 2:
’ +
‘’ +
‘’ +
‘’;
http.createServer(function (req, res) {
var body = "";
req.on('data', function (chunk) {
console.log('data: ' + chunk);
body += chunk;
});
req.on('end', function () {
console.log('Posted: ' + body);
res.writeHead(200);
res.end(postHTML);
});
}).listen(8080);
And this is how i send my HttpRequest
void AMyActor::ProcessRequest(const FString& Url)
{
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
FString TrimmedUrl = Url;
TrimmedUrl.Trim();
TrimmedUrl.TrimTrailing();
HttpRequest->SetURL(TrimmedUrl);
switch (RequestVerb)
{
case ERequestVerb::GET:
HttpRequest->SetVerb(TEXT("GET"));
break;
case ERequestVerb::POST:
HttpRequest->SetVerb(TEXT("POST"));
break;
case ERequestVerb::PUT:
HttpRequest->SetVerb(TEXT("PUT"));
break;
case ERequestVerb::DEL:
HttpRequest->SetVerb(TEXT("DELETE"));
break;
default:
break;
}
// Set content-type
switch (RequestContentType)
{
case ERequestContentType::json:
{
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
HttpRequest->SetContentAsString(TEXT("test"));
break;
}
default:
break;
}
// Execute the request
if (!HttpRequest->ProcessRequest()) {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Problem processing the request "));
}
else {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("success"));
}
}
The Verb is POST and the Url is http://localhost:8080/. As soon as i launch this on my browser (firefox 64 bit) i get the succes and it shows “Posted:” in the console. Am I missing something?