C# 如何在Unity3D游戏中设置授权标头?
我在尝试向Unity中的服务器发送C# 如何在Unity3D游戏中设置授权标头?,c#,unity3d,C#,Unity3d,我在尝试向Unity中的服务器发送授权头时遇到一些问题。我已经在正在移植到Unity的Windows Phone项目中完成了此操作,但是当我将请求发送到服务器时,它返回500内部服务器错误 这是我打电话的代码: string hash = Helper.GetHashString(); byte[] toEncodeAsBytes = System.Text.Encoding.UTF8.GetBytes(username + ":" + password); stri
授权
头时遇到一些问题。我已经在正在移植到Unity的Windows Phone项目中完成了此操作,但是当我将请求发送到服务器时,它返回500内部服务器错误
这是我打电话的代码:
string hash = Helper.GetHashString();
byte[] toEncodeAsBytes = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
string base64 = System.Convert.ToBase64String(toEncodeAsBytes);
Hashtable headers = new Hashtable();
headers["Authorization"] = "Basic " + base64;
StartCoroutine(Server.Authorize(Config.SERVER_URL + "/Auth/" + hash, LoginEventResponse, headers));
服务器。请授权:
public static IEnumerator Authorize(string path, DelegateEventFunction myEvent, Hashtable headers)
{
WWW www = new WWW(SERVER_URL + path, null, headers);
yield return www;
当www返回时,我得到上面提到的错误(500)。我移植的代码是:
string hash = Helper.GetHashString();
byte[] toEncodeAsBytes = System.Text.Encoding.UTF8.GetBytes(Model.Username + ":" + Model.Password);
string base64 = Convert.ToBase64String(toEncodeAsBytes);
HttpClient loginClient = new HttpClient();
loginClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64);
string loginResponse = await loginClient.GetStringAsync(Config.SERVER_URL + "/Auth/" + hash);
除了Units使用WWW而不是HttpClient之外,情况也差不多。也许这可以通过购买专业版来解决,让我可以访问本机库,但除了这一个,每个webcall都可以工作,我尝试在授权标题中发送。
有人给小费吗
编辑
我从日志中记下了:
Error X-Token: chars_and_numbers,,chars_and_numbers2
Error Exception: Sequence contains no elements in System.Core
谷歌表示编码有问题?我一直使用相同的方法,UTF8…服务器上出现内部错误,但这里只显示客户端代码。抛出错误的服务器代码是什么样子的?嗨,golergka,正如我提到的,我的Windows Phone项目运行得很好,我在问我是否做了错误的事情或者Unity中的任何事情,这仍然有助于诊断问题。你能至少包括Unity和Windows Phone项目发送到服务器的请求吗?@golergka ive从日志中添加了错误,但我仍然没有线索