Raised This Month: $51 Target: $400
 12% 

How to do a HTTP POST using a plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
waylaidwanderer
SourceMod Donor
Join Date: Aug 2012
Old 08-09-2013 , 02:40   How to do a HTTP POST using a plugin?
Reply With Quote #1

I'd like to be able to send an HTTP POST request with some parameters to a specific URL.
I'm actually not sure where to start - searching didn't seem to turn up anything concrete.

I understand I have options such as cURL, SteamTools or even Sockets, but what's the easiest way to accomplish this?
waylaidwanderer is offline
TheGodKing
BANNED
Join Date: Dec 2012
Location: PrintToChatAll("Aus
Old 08-09-2013 , 02:56   Re: How to do a HTTP POST using a plugin?
Reply With Quote #2

Sorry, I gave the wrong answer. I'm not sure about POST.

Where exactly are you sending the request?

Last edited by TheGodKing; 08-09-2013 at 03:07. Reason: Deleted old reply
TheGodKing is offline
waylaidwanderer
SourceMod Donor
Join Date: Aug 2012
Old 08-09-2013 , 03:04   Re: How to do a HTTP POST using a plugin?
Reply With Quote #3

Quote:
Originally Posted by TheGodKing View Post
If you are trying to open an motd to a url you can use ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)

Example:

PHP Code:
ShowMOTDPanel(client"My MOTD Panel""https://forums.alliedmods.net"MOTDPANEL_TYPE_URL); 
I'm not trying to do this at all. I'm trying to work with an API that requires you to send an HTTP POST request along with some parameters (such as SteamID64 for example).

Last edited by waylaidwanderer; 08-09-2013 at 03:04.
waylaidwanderer is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 08-09-2013 , 04:55   Re: How to do a HTTP POST using a plugin?
Reply With Quote #4

SteamTools is the simplest.

PHP Code:
SendRequest() {
    new 
HTTPRequestHandle:request Steam_CreateHTTPRequest(HTTPMethod_POST"http://www.example.com"); // Create the HTTP request
    
Steam_SetHTTPRequestGetOrPostParameter(request"herp""derp"); // Set post param "herp" value to "derp"
    
Steam_SendHTTPRequest(requestOnRequestComplete); // Send the request
}

public 
OnRequestComplete(HTTPRequestHandle:requestbool:successfulHTTPStatusCode:status) {
    
decl String:response[1024];
    
Steam_GetHTTPResponseBodyData(requestresponsesizeof(response)); // Get the response from the server
    
Steam_ReleaseHTTPRequest(request); // Close the handle

__________________

Last edited by Dr. McKay; 08-09-2013 at 04:55.
Dr. McKay is offline
waylaidwanderer
SourceMod Donor
Join Date: Aug 2012
Old 08-09-2013 , 05:18   Re: How to do a HTTP POST using a plugin?
Reply With Quote #5

Quote:
Originally Posted by Dr. McKay View Post
SteamTools is the simplest.
Thanks so much! I was fiddling with Sockets just now but this does seem a lot more straightforward. And if I have multiple parameters, I'd just need to add a few more of
PHP Code:
Steam_SetHTTPRequestGetOrPostParameter(request"herp""derp"); // Set post param "herp" value to "derp" 
right?
waylaidwanderer is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-09-2013 , 07:53   Re: How to do a HTTP POST using a plugin?
Reply With Quote #6

Correct.
__________________
11530 is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 08-11-2013 , 12:02   Re: How to do a HTTP POST using a plugin?
Reply With Quote #7

How to do this without steamtools?
__________________
neatek is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 08-11-2013 , 22:54   Re: How to do a HTTP POST using a plugin?
Reply With Quote #8

With the sockets, curl, or your own self written extension.
Dr. Greg House is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode