【发布时间】:2015-11-15 07:33:13
【问题描述】:
我似乎无法将 JSON 发布到网页 https://authserver.mojang.com/authenticate 并获得回复。 当我发布 JSON 时,它只是说
远程服务器返回错误:(400) Bad Request
我浏览了其他人编写的许多不同脚本,并通过将 Java 代码转换为 C# 创建了自己的脚本。无论如何,这是迄今为止效果最好的代码。
string authserver = "https://authserver.mojang.com/authenticate";
byte[] rawData = fs.GetBytes(**[JSON]**);
WebRequest request = WebRequest.Create(authserver);
request.ContentType = "application/json";
request.Method = "POST";
//request.ContentLength = rawData.LongLength;
WebResponse connection = request.GetResponse();
connection.ContentType = "application/json";
connection.ContentLength = rawData.LongLength;
Stream stream = connection.GetResponseStream();
stream.Write(rawData, 0, rawData.Length);
stream.Flush();
byte[] rawVerification = new byte[10000];
int count = stream.Read(rawVerification, 0, 10000);
编辑: 是否可以使用 webclient 执行此代码?
编辑: 它的输入无效,json 没有所需的正确数据
【问题讨论】: