cvona
Forum Replies Created
-
AuthorPosts
-
Hi Bob, I do not know if you saw my previous message. The problem of the WebRequestNode, is that inside is hardcoded headers[“Authorization”] = token.StartsWith( “Bearer ” ) ? token : “Bearer ” + token; while my header starts with “Basic”. I am trying to modify it, but I get this error when I add the script to the project: [CS0012] WebRequestNode.cs(351,45): The type ‘WWWForm’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘UnityEngine.UnityWebRequestModule, Version=0.0.0.0,
I had a look at the WebRequest node script. It does not work because the node is not good for making an authentication.
I decided to modify it to work the way I want. What I should do is the following:
static async Task<string> Autentication()
{
string ret = “”;
string credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes($”{StringUtils.CLIENT_ID}:{StringUtils.CLIENT_SECRET}”));
string postData = “grant_type=client_credentials”;
Console.WriteLine($”credentials: {credentials}”);HttpWebRequest request = (HttpWebRequest)WebRequest.Create(StringUtils.ACCESS_TOKEN_URL);
request.Method = “POST”;
request.ContentType = “application/x-www-form-urlencoded”;
request.Headers[“Authorization”] = $”Basic {credentials}”;using (var stream = new StreamWriter(request.GetRequestStream()))
{
stream.Write(postData);
}
try
{
using (var response = (HttpWebResponse)request.GetResponse())
using (var reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
Console.WriteLine(“Token Response: ” + result);// Estrai il token (usa un parser JSON se vuoi farlo in modo robusto)
var tokenStart = result.IndexOf(“access_token\”:\””) + 15;
var tokenEnd = result.IndexOf(“\””, tokenStart);
ret = result.Substring(tokenStart, tokenEnd – tokenStart);
}}
catch (WebException ex)
{
using var errorResponse = (HttpWebResponse)ex.Response;
using var reader = new StreamReader(errorResponse.GetResponseStream());
string errorText = await reader.ReadToEndAsync();
Console.WriteLine(“Errore server: ” + errorText);
ret = “0”;
}
return ret;}
By trying to modify the node, I also get some errors. The main one is [CS0012] WebRequestNode.cs(351,45): The type
‘WWWForm’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘UnityEngine.UnityWebRequestModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null’, which, as you can see here, I also have it when uploading the WebRequestNode from the directory with all the examples. I tried to include “using UnityEngine.Networks;” but it does not solve the problem.In my test, I did not include everything, since I wanted to test if it was working well or not. I was expecting an error message as output value, but this did not work. Should it work in your opinion? Why does async not work? It was very difficult to find the reason since F12 doesn’t work in the PH, and the files did not give errors during the upload.
I am not sure I can send you everything since the request is for authenticating on the server, maybe the best is if you send me an example working that I can try to replicate.
Thank you for your help.
Hi Jason,
After removing some of the assets, the problem disappeared, and then it happened again. It looks to me that the problem started again after I uploaded a video. By looking better, it looks like the avatar starts to fly. I cannot reproduce it because it is random, but I got it several times. It looks like it is triggered by some assets, but I do not get what they have in common.
Unfortunately, what you suggested is what I tried at the beginning, but the result, for some reason, is 2. To get 1, I have to do the following:
If I do this the first time it is fine, but for action that occurs later on, this resets the score to 0, so the result is always 1. In the case I do here as you suggested, I get 3 instead of 2. Why is this happening?
-
AuthorPosts