Search code examples
javahttpclientsteam

To login to Steam need a RSA key. I have created a post request with HttpClient from java 11 ot get the key but it returns Body : {"success":false}


I am trying to create steam bot with java. I have the following code that posts to steam :

HttpClient client = HttpClient.newBuilder().build();
        String data = "{\"username\" : " + "\"" + USERNAME + "\"}";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://store.steampowered.com/login/getrsakey"))
                .headers("User-Agent", "Mozilla/5.0", "Content-Type", "application/json; charset=UTF-8")
                .POST(HttpRequest.BodyPublishers.ofString(data))
                .build();

        try{
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            System.out.println(response);
            System.out.println("Body : " + response.body());
            System.out.println("StatusCode : " + response.statusCode());

        }
        catch(IOException | InterruptedException e){
            System.out.println("IOException : " + e.getMessage());
        }

It returns the following :

(POST https://store.steampowered.com/login/getrsakey) 200
Body : {"success":false}
StatusCode : 200

I have done this with python using the Requests and it works. Following is code that works with python :

import requests;

print(requests.post("https://steamcommunity.com/login/getrsakey/", params={"username": "AdwaitBot"}).content)

I dont understand what is the problem with my java code. Any help or advice will be appreciated. Thank you for the help.


Solution

  • params in your python code means request params in URI rather than the request body. The actual request you make in python is POST https://steamcommunity.com/login/getrsakey/?username=AdwaitBot In java, you should form your URI accordingly.