SA-MP Forums Archive
SOME WAY TO SEND A POST REQUEST - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SOME WAY TO SEND A POST REQUEST (/showthread.php?tid=671561)



SOME WAY TO SEND A POST REQUEST - markjonh - 02.01.2020

Good community, I want to know how I can send data with the plugin a_http but using post because in the example of the wiki it is only with get


Re: SOME WAY TO SEND A POST REQUEST - Danbo7 - 03.01.2020

Just use GET instead - pm me if u need help with this


Re: SOME WAY TO SEND A POST REQUEST - CXdur - 03.01.2020

Quote:
Originally Posted by Danbo7
View Post
Just use GET instead - pm me if u need help with this
But why?

Quote:
Originally Posted by markjonh
View Post
Good community, I want to know how I can send data with the plugin a_http but using post because in the example of the wiki it is only with get
Code:
format(query, sizeof(query), "user=%s&email=%s&code=%s&hash=%s&token=thetoken", urlencode(PlayerName(playerid)), urlencode(email), urlencode(code), urlencode(verification_hash));

// Send the verification email
HTTP(playerid, HTTP_POST, "activations.example.com/include/verification_email.php", query, "HTTP_SendVerificationEmail");

forward HTTP_SendVerificationEmail(index, response_code, data[]);
public HTTP_SendVerificationEmail(index, response_code, data[])
{
	if (response_code == 200)
	{
		LOG_DEBUG_F("Success: %s", data);
	}
	else
	{
		LOG_DEBUG_F("Failed: %d", response_code);
	}
}
Example above for POST request. You just have to use the data parameter for POST requests.
Code:
native HTTP(index, type, url[], data[], callback[]);
GET Request below to show similarities.
Code:
// Trace the IP address
new ip_locate_q[60];
format(ip_locate_q, sizeof(ip_locate_q), "thegeoapi.com/csv/%s?fields=status,country,city", PlayerIP(playerid));
HTTP(playerid, HTTP_GET, ip_locate_q, "", "HTTP_OnIpTraced");

forward HTTP_OnIpTraced(index, response_code, data[]);
public HTTP_OnIpTraced(index, response_code, data[])
{
	new connect_msg[128],
		connect_msg_admin[128],
		connect_msg_panel[78];
....
}