unity3d - 遇到无效的重定向。缺少位置标头。统一问题
问题描述
我正在使用 Unity WWWForm 将许可证验证请求发布到 URL。该代码在 Unity 5.6 中有效,但在 Unity 2017.3.1f1 中无效。我也在 Unity 2018 中尝试过。它没有用。
这是错误消息:遇到无效重定向(缺少位置标头?)
这是我正在使用的代码。
void Awake() {
Instance = this;
WWWForm form = new WWWForm ();
mainHeader = form.headers;
mainHeader ["Authorization"] = "Basic " + System.Convert.ToBase64String (System.Text.Encoding.ASCII.GetBytes ("dummyId:#dummyPassword"));
}
public void HitForLicence(){
string jsonData = JsonUtility.ToJson (new LicenseData {
LICENCE_KEY="kwsnfdksfksnf",
MACHINE_IP="192.168.1.1"
});
Debug.Log (jsonData);
byte[ ] postData = System.Text.Encoding.ASCII.GetBytes (jsonData);
//headers ["Authorization"] = "Basic " + System.Convert.ToBase64String (System.Text.Encoding.ASCII.GetBytes ("unity:@piun!ty"));
if (mainHeader.ContainsKey ("Content-Type")) {
mainHeader ["Content-Type"] = "application/json";
} else {
mainHeader.Add ("Content-Type", "application/json");
}
WWW www = new WWW (LicenseURL, postData, mainHeader);
StartCoroutine (CheckForLicense (www));
}
public IEnumerator CheckForLicense (WWW www)
{
Debug.Log("Check For License..");
yield return www;
//if (www.isDone ) {
if (www.error != null) {
ClearKeyBox ();
print (www.error);
}
else {
print (www.text);
jsonNode = SimpleJSON.JSON.Parse(www.text);
print ("MSG "+ jsonNode["MSG"].ToString());
}
//}
if (jsonNode != null && jsonNode["MSG"].Equals(ValidStr)) {
HandleTextFile.WriteString(_SystemMACAddress+"-"+keyEntered);
// Next screen
} else {
ClearKeyBox ();
}
}
有人遇到过这个吗?请帮忙。
解决方案
WWW
在 Unity 2018 下我也遇到了一些问题。
目前我正在使用UnityWebRequest
- 我认为WWW
已经过时,但我找不到任何参考。
基本上像这样更改您的代码:
...
UnityWebRequest www = UnityWebRequest.Post(LicenseURL, form)
StartCoroutine (CheckForLicense (www));
}
public IEnumerator CheckForLicense (WWW www)
{
Debug.Log("Check For License..");
...
我认为您必须通过设置头部SetRequestHeader
并将您的帖子数据放入 WWWForm ...
我现在无法检查它......希望它有帮助!
推荐阅读
- elasticsearch - Kibana 6.3.0 - “共享保存的仪表板” - 短仪表板
- bash - 带有 for 循环的无效算术运算符(错误标记为“”)
- python - 使用并行运行 html2text
- akka - 有没有办法让一个 Akka 节点知道另一个 Akka 节点是否重新启动
- vba - 尽管计算设置为手动,但在打开工作簿时不会禁用计算
- visual-studio-code - 每次在 VS Code 中打开新的终端窗口时,如何运行一些命令?
- javascript - AWS IoT Core 连接被经过身份验证的 Cognito 用户拒绝,带有附加策略 [MQTT over WSS]
- sql - 使用命令复制在 postgres 中出现变量连接问题
- android - Android Intent Share 无法正常工作
- corda - 使用 network-bootstrapper 生成节点信息需要带有 devMode=false 的证书