Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Post Request Implementation #53

Merged
merged 3 commits into from
Apr 13, 2023
Merged

HTTP Post Request Implementation #53

merged 3 commits into from
Apr 13, 2023

Conversation

aoqia194
Copy link
Contributor

@aoqia194 aoqia194 commented Apr 9, 2023

I have written code to support POST HTTP requests, just like GET HTTP request (httpget).
Function in production will look like this: httppost(url <string>, data <array/json string>, headers <array>)

This will solve issues #46 and #32 too.

@@ -80,7 +80,53 @@ namespace utils::http

if (curl_easy_perform(curl) == CURLE_OK)
{
return {std::move(buffer)};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only exists because of my previous commit.

scripting::script_value http_post(const gsc::function_args& args)
{
const auto url = args[0].as<std::string>();
const auto headers = args[1].as<utils::http::headers>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where linker error is happening mainly. Using utils::http::headers for some reason causes that error. I've even tried just using std::unordered_map<std::string, std::string> and it causes the same error.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because there is no convertion from script_value to utils::http::headers or any std::unordered_map:

const auto array = args[0].as<scripting::array>();
const auto keys = array.get_keys();
utils::http::headers headers{};
for (const auto& key : keys)
{
	const auto value = array[key];
	if (!key.is<std::string>() || !value.is<std::string>())
	{
		continue;
	}

	const auto key_str = key.as<std::string>();
	headers[key_str] = value.as<std::string>();
}

This was referenced Apr 9, 2023
It works POGGERS
@aoqia194 aoqia194 marked this pull request as ready for review April 9, 2023 19:53
@aoqia194
Copy link
Contributor Author

aoqia194 commented Apr 9, 2023

Thank you for the help fed. Such an obvious solution and here I was going crazy LOL...

@alicealys alicealys merged commit 8127edc into alicealys:main Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants