[英]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.我正在尝试使用 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.我已经使用请求使用 python 完成了此操作,并且可以正常工作。 Following is code that works with python:以下是适用于 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.我不明白我的 java 代码有什么问题。 Any help or advice will be appreciated.任何帮助或建议将不胜感激。 Thank you for the help.感谢您的帮助。
params
in your python code means request params in URI rather than the request body. params
代码中的参数表示 URI 中的请求参数,而不是请求正文。 The actual request you make in python is POST https://steamcommunity.com/login/getrsakey/?username=AdwaitBot
In java, you should form your URI accordingly.您在 python 中提出的实际请求是POST https://steamcommunity.com/login/getrsakey/?username=AdwaitBot
在 Z93F725A07423FE1C889F448B33D21F46 中,您应该相应地形成您的URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.