如何在Unity3d宽度UnityWebRequest中处理NTLM身份验证。 我做了一些步骤:
我试试这段代码:
string url = "some_url";
public void Start()
{
StartCoroutine(Test(1, url, OnStep1));
}
private void OnStep1()
{
StartCoroutine(Test(2, url, OnStep2));
}
private void OnStep2()
{
}
private void AddHeaders(UnityWebRequest request)
{
var value = "NTLM " + System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("login"));
request.SetRequestHeader("Authorization", value);
}
private IEnumerator Test(int step, string url, Action Callback)
{
var webRequest = UnityWebRequest.Get(url);
if (step == 2)
{
AddHeaders(webRequest);
}
yield return webRequest.Send();
if (webRequest.isNetworkError)
{
Debug.Log(" Error: " + webRequest.error);
}
else
{
Debug.Log("xxx step " + step + " responseCode " + webRequest.responseCode);
var dict = webRequest.GetResponseHeaders();
Debug.Log("xxx dict " + dict.Count);
foreach (var el in dict)
{
Debug.Log("xxxx step " + step + " header " + el.Key + " " + el.Value);
}
Callback();
}
}