我正在从事一个游戏化项目,其目标是使用 Unity 构建 WebGL 游戏,并使用 canvas LMS API 将最终分数作为作业成绩发布。我需要知道两件事:现在如何使用不记名令牌进行身份验证(我已经知道如何创建令牌,以后需要使用 auth 2.0)以及如何使用 UnityWeb 请求或类似方法发布作业成绩。我尝试使用restsharp,vs代码识别它,但Unity没有。还尝试与 node.js 建立连接,Unity 和 node.js 连接成功,但我使用的节点包装器不起作用。
在最糟糕的情况下,我希望能够对作业发表评论(我会将最终成绩作为字符串传递)。
这是我用 httpWebRequest 尝试过的:
string api_token = "bearer token here";
//initializing HttpWebRequest object
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("domain here");
IWebProxy theProxy = request.Proxy;
if (theProxy != null)
{
theProxy.Credentials = CredentialCache.DefaultCredentials;
}
CookieContainer cookies = new CookieContainer();
request.UseDefaultCredentials = true;
request.CookieContainer = cookies;
request.ContentType = "application/json";
request.CookieContainer = cookies;
// write the "Authorization" header
request.Headers.Add("Authorization", "Basic " + api_token);
request.Method = "POST";
// get the response
//WebResponse response = request.GetResponse();
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
Debug.Log(reader.ReadToEnd());
}
我需要节点包装器来进行身份验证和发布请求。节点包装器:c10。我已经尝试过很多次和 node-canvas-api
我可以访问 api 并使用邮递员发布。