【发布时间】:2021-07-09 11:28:33
【问题描述】:
我正在从事一个游戏化项目,其目标是使用 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. I've tried with this one a lot 和 node-canvas-api
我可以访问 api 并使用邮递员发帖。
【问题讨论】:
-
你能分享你尝试过的例子吗?如果 Unity 和节点连接成功,您还需要哪些节点包装器?他们需要什么?如果是 API 访问,既然你已经熟悉了 api,可以不访问吗?
-
我已经更新了我的问题,因为评论部分无法处理这么多。
-
有用的更新,谢谢。你可以拦截和检查请求吗?比较线路上的内容,因为它应该都是可读的(一旦 TLS 解包)。
标签: unity3d httpwebrequest unity-webgl canvas-lms unitywebrequest