Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UNITY SIDE
- IEnumerator Foo()
- {
- var N = JSON.Parse("{}");
- N["input1"] = input1.text;
- N["input2"] = input2.text;
- string encrypted = Encrypt(N.ToString(), GenerateEncryptionKey);
- print("ENSEND: \n" + encrypted);
- using (UnityWebRequest www = UnityWebRequest.Post(targetURL, encrypted))
- {
- yield return www.SendWebRequest();
- if (www.isHttpError || www.isNetworkError)
- {
- Debug.LogError(www.error + "\n" + www.downloadHandler.text);
- onFail?.Invoke();
- }
- else
- {
- onSuccess?.Invoke();
- print(www.responseCode + " : " + www.downloadHandler.text);
- }
- }
- yield break;
- }
- //FUNCTION SIDE
- [FunctionName("UserAuthentication")]
- public static async Task<IActionResult> Run(
- [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
- ILogger log)
- {
- log.LogInformation("C# HTTP trigger function processed a request.");
- string name = req.Query["name"];
- string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
- try
- {
- requestBody = Decrypt(requestBody, "Dracon");
- } catch (Exception e)
- {
- //Throwing exception here due to escaped characters
- return new BadRequestObjectResult(e.Message + "\n" + requestBody + "\n" + Regex.Unescape(requestBody));
- }
- JSONNode N = null;
- try
- {
- N = JSON.Parse(requestBody);
- if (N["input1"] != "")
- {
- name = N["username"];
- return (ActionResult)new OkObjectResult($"Hello, {name}");
- } else if (name != "")
- {
- return (ActionResult)new OkObjectResult($"Hello, {name}");
- } else
- {
- return new BadRequestObjectResult("Invalid object syntax");
- }
- } catch (Exception e)
- {
- return new BadRequestObjectResult("Invalid JSON provided. N = " + (N != null).ToString() + "\n" + requestBody + "\n" + e.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement