Closed Kxnrl closed 4 years ago
Simple plugin to test that.
#include <system2>
#pragma semicolon 1
#pragma newdecls required
public void OnPluginStart()
{
ServerCommand("sv_hibernate_when_empty 0");
System2HTTPRequest request = new System2HTTPRequest(System2HTTPRequest_Callback, "https://api.kxnrl.com/upload/upload.php");
request.SetVerifySSL(true);
//request.SetHeader("Expect", "");
request.FollowRedirects = true;
request.AddPostFormData(1, "motd", 10, "motd.txt");
request.AddPostFormData(1, "gameinfo", 10, "gameinfo.txt");
request.POST();
}
void System2HTTPRequest_Callback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
{
if (!success)
{
LogError("Failed to POST: %s", error);
return;
}
PrintToServer("Success! -> %d", response.StatusCode);
char content[128];
for (int found = 0; found < response.ContentLength;) {
found += response.GetContent(content, 128, found);
PrintToServer(content);
}
}
use curl_mime_init instead closed
I don't know any other way to post a form. This is easy way to post file or data for me. I don't like uploading files via FTP. Maybe the function name is stupid :(