我试图通过XboxLive验证一个用户,我遇到了一些麻烦,我正在阅读this文章,我无法通过第一步,它总是返回400: Bad Request
。我做了一些挖掘,有些人说要把d=
放在accessToken之前,但这没有帮助。
public void getXboxLiveToken() throws IOException{
if (this.accessTokenJson == null) getAccessToken();
Header[] headers = new Header[2];
headers[0] = applicationJsonContentTypeHeader;
headers[1] = applicationAcceptJsonHeader;
HttpPost httpPost = new HttpPost(SIGNIN_XBL_URL);
httpPost.setHeaders(headers);
String jsonString = this.gson.toJson(new SignIntoXBLJson(this.accessTokenJson.getAccessToken()));
StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
httpPost.setEntity(requestEntity);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
byte[] responseBytes = response.getEntity().getContent().readAllBytes();
System.out.println(response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase());
System.out.println(new String(responseBytes));
}
}
杰森
{
"Properties": {
"AuthMethod": "RPS",
"SiteName": "user.auth.xboxlive.com",
"RspTicket": "d=<Access Token>"
},
"ReplyingParty": "http://auth.xboxlive.com",
"TokenType": "JWT"
}
1条答案
按热度按时间vm0i2vca1#
我也花了一些时间才弄明白,但我最终找到了这篇文章:Mojang API Documentation很好地总结了这一点。
请求必须是
'POST'
请求,urlhttps://user.auth.xboxlive.com/user/authenticate
具有以下标头:Content-Type: application/json
Accept: application/json
并带有以下正文:
结果应类似于:
我最终实现的解决方案如下所示:
我使用的是Unirest库,它大大简化了代码