简体   繁体   中英

HTTP Post request handler in java

I hope someone will be able to help me understand how to create an endpoint HTTP server listener. I'm trying to create a POST request handler that can save all post requests made to a text file.

The purpose is for a Game state integration between My application and Counter-Strike. Ive read their documentation ( csgo GSI documentation ) and the example given in here is almost exactly what I'm looking for. But its written in nodejs and I will need it to work with Java.

I have only been able to create a HTTPServer but can't seem to understand how I can create a POST request handler which records the data sent to "data" request.

How can I create a handler which can record all requests sent to data?

I believe the easiest & fastest way is to grab a SpringBoot app from https://start.spring.io/ (add Web dependency). And then create a Spring @RestController like that:

@RestController
@RequestMapping(value = "/cs")
public class CsController {

    @RequestMapping(value = "", method = RequestMethod.POST)
    public void processCsData(@RequestBody CsData csData) {
        processCsData(csData);
    }

}

where CsData is a POJO class that they send to you. processCsData() is your method to do whatever you like with the data.

Now you need to host it somewhere so that it would be reachable from the Internet or you can use https://ngrok.com/ to create a tunnel for test purposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM