I want to send requests from a UE4 C ++ game to my PHP script so that it interacts with the mysql database

I have been searching for an Internet for about 3 days, and I am stuck with this.

I have a MySQL database and a PHP script, as well as a game made in UE4. UE4 uses C ++.

So now I want to send requests from a C ++ game to a PHP script and interact with the database. For example, create an account or login. I also want to pass the result of the mysql query from a PHP script to my C ++ class. I tried to use HttpRequest, but I cannot get data from php in C ++ with this.

Maybe you can, but I don’t understand this at all. In addition to what I have achieved so far, you can send a POST request from a game to a PHP script and pass variables so that the script uses them to execute the mysql request. But how can I transfer data from a php file to C ++ now? The answer I get is always the whole site (head and body), and I don’t know where I can save the result of the request to pass it to C ++ code.

I'm a novice beginner here, so it's easy on me. I read so many different posts and blogs that my brain hurts like hell): I hope someone can tell me how to do it easily or at least give me a hint about what I need for Google and what I can use . I don't need a complete tutorial, just a library name is better than Http.h (if just HttpRequest couldn't handle it) would be enough. ): I'm so sad...

Exi

+4
source share
2 answers

The PHP script should reconfigure the HTTP response with a minimum minimum. It doesn't even have to be an HTML document:

<?php

    // file: api.php

    $param = $_POST['myparam'];

    $foo = bar($param); // $foo contains e.g. "1,ab,C"
    echo $foo;          // if you opened http://myhost.com/api.php in a browser
                        // all you would see is "1,ab,C"
                        // (which is not a valid HTML document, but who cares)

?>

HTTP ( , ) . (XML JSON - ).

+3

json unreal , json php script. Json php - .

<?php
    $obj['userid'] = 5476;
    $obj['foo'] = 'bar';
    echo json_encode($obj);
php?>

-

{"userid":5476,"foo":"bar"}

, script, json-.

FString TheStuffIGotFromTheServer;
TSharedPtr<FJsonObject> ParsedJson;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(TheStuffIGotFromTheServer);
if (FJsonSerializer::Deserialize(JsonReader, ParsedJson))
{
    FString foo = ParsedJson.GetStringField("foo");
    double UserId = ParsedJson.GetNumberField("userid");
}

json docs, , .

+1

All Articles