Hot Door CORE Forum
Explaining InternetPOST _data and how it is sent - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: Explaining InternetPOST _data and how it is sent (/showthread.php?tid=315)



Explaining InternetPOST _data and how it is sent - zero - 04-20-2022

So i am working a bit with GET and POST requests right now, and have been trying to understand the format that my data is being sent out as.

In the documentation you can see the parameters are as follows:

Parameters

url_
HTTP(S) URL to read, as UTF-8
data_
Dictionary of data to be JSON-encoded and sent to url_; root-level members of the dictionary will be used as individual POST arguments, and the member values will be individually JSON-encoded as POST argument values
success_
Callback to perform when the request completes successfully
failure_
Callback to perform when the request fails


I understand everything about this so far, minus the data_ param, which is slightly confusing (or i am just a noob). I am structuring my data using nlohman::json library to create my inital json data, then i store it inside of a dictionary pref for the ::InternetPOST type.

It accepts it and i get an error back from the server i am pinging which definitely means that the data is going through, but i cannot seem to understand the format that the data is being sent out as.

From reading the docs it seems like if i give it the following json ():
{
    "application": {
        "name": "my_application",
        "version": 0.0.1,
        "os": "MACOS"
    }
};

Then i use the following to format it and pass it into my hdi::core::InternetPost request:
**.dump() comes from the nlohman::json library and returns a string representation of the json data.

std::unique_ptr<hdi::core::PrefData> _dict = hdi::core::DictionaryPref::parse(data.dump());


this->__connectToPOST = hdi::core::InternetPOST::Async("http://localhost:9999/connect", *dynamic_cast<hdi::core::DictionaryPref*>(_dict.get()), HDI_CORE_CALLBACK(Plugin, this, successfulPost), HDI_CORE_CALLBACK(Plugin, this, unsuccessfulPost));

So if that is the case - i am just curious if anyone knows how the data goes out and is made in the request. 

What i understand is it comes back as "application/$stringshereasparameters?";

Let me know if anyone can help!!


RE: Explaining InternetPOST _data and how it is sent - garrett - 04-26-2022

I suppose the documentation for the data_ param could be worded a bit better; the dictionary will be JSON-encoded automatically by the InternetPOST class when communicating with the target server. As such, you do not need to manually JSON encode anything yourself first - just fill a hdi::core::DictionaryPref as needed and pass it to InternetPOST.

Similarly, when you receive a response, it is merely handled as a string. However, if the string contains JSON-encoded data, you can pass the string to the hdi::core::PrefData::parse() method to convert the string's data into the appropriate structure of PrefData subclasses in memory.