Raised This Month: $32 Target: $400
 8% 

REST API example (REST in Pawn) to send a POST request


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 08-17-2019 , 12:50   REST API example (REST in Pawn) to send a POST request
Reply With Quote #1

Hello, as the title says, can someone write a example script with REST in Pawn to send a POST reqeust, the script should send something like this:

http://example.com/myfile.php?steamid={STEAMID}&points={points}

in sourcemod example:
...("http://example.com/myfile.php?steamid=%s&points=%i", steamid, points);
or how ever...

thanks.

Last edited by iskenderkebab33; 08-17-2019 at 12:59.
iskenderkebab33 is offline
timtam95
Member
Join Date: Feb 2018
Old 08-17-2019 , 16:33   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #2

http://example.com/myfile.php?steamid={STEAMID}&points={points} is a GET request, not a POST. And if all you are doing is sending a GET request to a web server, you don't need a JSON API.
timtam95 is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 08-17-2019 , 17:35   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #3

Quote:
Originally Posted by timtam95 View Post
http://example.com/myfile.php?steamid={STEAMID}&points={points} is a GET request, not a POST. And if all you are doing is sending a GET request to a web server, you don't need a JSON API.
how can i do this without a extension?
iskenderkebab33 is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 08-17-2019 , 17:42   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #4

You can't do this without extensions. SourceMod doesn't provide for plugins any API for working with network (sockets) or web-sites (HTTP).
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 08-17-2019 , 18:50   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #5

so... can you guys do a example with POST or GET please.
iskenderkebab33 is offline
timtam95
Member
Join Date: Feb 2018
Old 08-17-2019 , 19:11   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #6

Quote:
Originally Posted by iskenderkebab33 View Post
so... can you guys do a example with POST or GET please.
I just edited the example that came with the Connect extension:

// example for the socket extension

#include <sourcemod>
#include <socket>

public Plugin:myinfo = {
name = "socket example",
author = "",
description = "",
version = "",
url = ""
};

public OnPluginStart() {
// create a new tcp socket
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);

// connect the socket
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "example.com", 80)
}

public OnSocketConnected(Handle:socket, any:arg) {
// socket is connected, send the http request

new String:requestStr[100];
new points = 0;
new String:steamid[256];
Format(steamid, sizeof(steamid), "1234567890");

Format(requestStr, sizeof(requestStr), "GET /myfile.php?steamid=%s&points=%d HTTP/1.0\r\nHost: example.com\r\nConnection: close\r\n\r\n", steamid, points);
SocketSend(socket, requestStr);
}

public OnSocketReceive(Handle:socket, String:receiveData[], const dataSize, any:hFile) {

}

public OnSocketDisconnected(Handle:socket, any:hFile) {
// Connection: close advises the webserver to close the connection when the transfer is finished
// we're done here

CloseHandle(socket);
}

public OnSocketError(Handle:socket, const errorType, const errorNum, any:hFile) {
// a socket error occured

LogError("socket error %d (errno %d)", errorType, errorNum);
CloseHandle(socket);
}
timtam95 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 08-17-2019 , 19:37   Re: REST API example (REST in Pawn) to send a POST request
Reply With Quote #7

Curious but why use socket if you're using it similar to other http extensions and just opening and closing the connection?
Mitchell 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 12:49.


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