How can I set up a listener for HTTP POST's?

I want to post some data to Roblox with my form app on VS Code 2019 (C#).
Here is my C# code:

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string text;

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox textBox = sender as TextBox;
            text = textBox.Text;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WebRequest request = WebRequest.Create("http://127.0.0.1/");
            request.Method = "POST";
            request.ContentLength = text.Length;

            Stream dataStream = request.GetRequestStream();
            byte[] byteArray = Encoding.UTF8.GetBytes(text);
            dataStream.Write(byteArray, 0, byteArray.Length);
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

I want to get this POST data from Roblox Studio, how can I do that?

Not really familiar with C# but you would have to use HTTPService

And you’ll need to enable HTTP Service in the game settings if you are gonna use this

(Try looking at GetAsync and PostAsync)

I know these, I’m searching for a method which will listen for HTTP POST’s to this URL.

The only method I’ve used before is somewhat slow and could use up a lot of resources if you’re not careful but i’ll say it anyway:

  1. send the post request to a dedicated server
  2. make the server echo the request back into a file that everyone can see
    (e.g. if i send a post request to https://mygameserver.com/request.php, then it should echo back everything into https://mygameserver.com/lastRequest.txt)
  3. Make ur roblox game do a GET request to that file every second or two and check for differences.
    If it’s different than the last cached file then it’s a new request

code example:

request.php:
<?php
$data = $_POST["someData"];
if (isset($data)) {
$storedDataFile = fopen("lastRequest.txt", "w");
fwrite($storedDataFile, $data);
fclose($storedDataFile);
}
?>
Roblox-side code:

local lastCachedData = ""
while wait(2) do
    local newData = game:GetService("HttpService"):HttpGetAsync("https://mygameserver.com/lastRequest.txt")

   if (newData ~= lastCachedData) then
      -- do something with ur new data
      lastCachedData = newData
   end
end

note this method is VERY unsafe if you’re POSTing private data that nobody should be able to read, but if you’re fine with them being able to read it then this should work fine

1 Like

Yeah I thought the same, thanks for clearing it up. Will it work with a local server? I’m doing this for testing purposes only, if I decide to use in games then I’ll look for a server.

im not sure if itll work for a local server even when only testing in studio
i know roblox does https checks before making a connection so u might have to do some weird stuff to ur local server to make it work

1 Like

A google says

tl;dr use HttpListener Class (System.Net) | Microsoft Docs

Also this forum isn’t really a .NET forum

Everyone can do a “google” please only reply if you have an idea. Also I know that C# has a HttpListener class but I want this to be on Roblox rn. I know this forum isn’t a .NET forum but it involves Roblox a lot.

Oh. You can’t do that. There’s no hosting a web server on Roblox.

You could reverse the connection (so your C# code is a server) and implement long-polling or something.