如何在 Unity3d 宽度 UnityWebRequest 中处理 NTLM 身份验证。我做了步骤:
- 向某个 url1 发送简单的请求。接收带有标题 WWW-Authenticate Negotiate,NTML 的响应
- 向 url1 发送请求,标题为“Authorization”,值为“NTML”+ System.Convert.ToBase64String(Text.Encoding.UTF8.GetBytes(login) 我必须得到哈希码,但我再次得到相同的响应(在第 1 步)
我试试这段代码:
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();
}
}