我在Unity3D和我的网站页面中有注册和登录页面,当我将寄存器或登录数据从Unity3D发布到我的网站(Magento CMS)时,请发送到我自己的错误“不可能进行必要的数据倒带”,然后查看我的请求在HTTPANALYZER应用程序中,我发现Unity3D无法接受Get cookie字符串。登录或注册用户后如何从Web获取cookie?我的Unity3D代码:

    var form = new WWWForm();
    form.AddField( "SN", SystemInfo.deviceUniqueIdentifier.ToString());
    form.AddField( "UserName ", UserName );
    form.AddField( "year",Year );
    form.AddField( "month", Month );
    form.AddField( "day", Day );
    form.AddField( "dob",Year+"/"+Month+"/"+Day );
    form.AddField( "gender", Gender );
    form.AddField( "password", Pass );
    // Create a download object
    var download = new WWW(URL, form);
    // Wait until the download is done
    yield download;
    // show the Results
    Debug.Log(download.text);   
    if(download.error != null)
    {
        Debug.Log("Err :"+download.error);
        Flag = "1"; 
    }
有帮助吗?

解决方案

通常,当您尝试加载重定向时,您会获得“不可能的数据倒带”。我认为您不能与“关注重定向”选项团结起来。

我不知道洋红色CMS,所以我无法告诉您如何纠正此问题。对于您的cookie问题,这很简单:您只需要从第一个通话中拦截标题“ set-cookie”,然后在下一个呼叫中将带有“ cookie”的标头发送回:

#pragma strict

import System.Collections.Generic;

var url:String = "";
var cookie:String = "";

/// interface
private var stringToEdit:String = "";
function OnGUI(){
    if (url!="" && GUI.Button(Rect(10,10,200,30),"Click"))
        StartCoroutine(LoadData());

    stringToEdit = GUI.TextArea (Rect (10, 50, 600, 400), stringToEdit);
}
/// debug
function Debug(s:String){
    stringToEdit += s+"\n";
}

function LoadData():IEnumerator{
    Debug(url);

    var form : WWWForm = new WWWForm();

    var time:String     = System.DateTime.Now.Ticks.ToString();
    form.AddField("time", time);

    // construct your header calls
    var headers : Hashtable = form.headers;
    if(cookie!="")
        headers["Cookie"] = cookie;

    var www : WWW = new WWW(url, form.data, headers);

    yield www;

    if(!www.error){
        Debug(www.text);

        // get the cookie and keep it
        if(www.responseHeaders.ContainsKey('SET-COOKIE')){
            var data:String[] = www.responseHeaders['SET-COOKIE'].Split(";"[0]);
            if(data.length>0){
                cookie = data[0];
            }
        }

    }else
        Debug(www.error);
    // debug
    for(var header:KeyValuePair.<String, String> in www.responseHeaders)
        Debug(header.Key+" "+header.Value);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top