我尝试验证用户使用我自己的启动器玩《我的世界》的原因(因为此启动器将我们需要在服务器(我的服务器)上播放的所有mod都安装了),但是即使我跟随Tutos,在httpWebRequest上也会出现错误:
远程服务器返回错误:(403)禁止。
这是代码:
public SecureString ObtainAccessToken(SecureString _User, SecureString _Pass)
{
var Access_Token = String.Empty;
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://authserver.mojang.com/authenticate");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.ProtocolVersion = HttpVersion.Version10;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"agent\":{\"name\":\"Minecraft\",\"version\":1},\"username\":\"" + Login.ToInsecureString(_User) + "\",\"password\":\"" + Login.ToInsecureString(_Pass) + "\",\"clientToken\":\"6c9d237d-8fbf-44ef-b46b-0b8a854bf391\"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
Access_Token = streamReader.ReadToEnd();
}
}
return Login.ToSecureString(Access_Token);
}
Sharko。