Hi Unity and Microsoft PRO! I am trying to use the Microsoft Bing Text to Speech API in Unity , this API requires an AccessToken , which will be passed in the request header. to get this token, I sent my authentication key to the βOcp-Apim-Subscription-Keyβ header, and the API will return an access token, which I can use next, is an API test that reconfigures the token in Postman.

So, this is the code for this, but it does not work.
using System.Collections; using System.Collections.Generic; using System.Xml.Linq; using UnityEngine; using UnityEngine.Networking; public class Test : MonoBehaviour { public static readonly string accessUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; public string accessToken; public void Start() { WWWForm wwwForm = new WWWForm(); Dictionary<string, string> headers = wwwForm.headers; headers["Ocp-Apim-Subscription-Key"] = "a66ec1e2123784hf39f22e2dc2e760d13x"; UnityWebRequest www = UnityWebRequest.Post(accessUri, wwwForm); StartCoroutine(RequestToken(www)); } public IEnumerator RequestToken(UnityWebRequest www) { yield return www; if (www.error == null) { Debug.Log("downloadedBytes : " + www.downloadedBytes); Debug.Log("certificateHandler : " + www.certificateHandler); Debug.Log("chunkedTransfer : " + www.chunkedTransfer); Debug.Log("downloadHandler : " + www.downloadHandler); Debug.Log("downloadProgress : " + www.downloadProgress); Debug.Log("isDone : " + www.isDone); Debug.Log("isNetworkError : " + www.isNetworkError); Debug.Log("method : " + www.method); Debug.Log("redirectLimit : " + www.redirectLimit); Debug.Log("responseCode : " + www.responseCode); Debug.Log("uploadedBytes : " + www.uploadedBytes); Debug.Log("useHttpContinue : " + www.useHttpContinue); } else { Debug.Log("Error" + www.error); } var p = www.downloadHandler.data; Debug.Log("Access token: " + p); } }
Result of this code:

I already tried the WWW class , but it did not work! and System.Net.Http , but Unity will not accept this library: /
Is there a way to do this, please?
source share