3

我在我的 C# (Xamarin) 应用程序中使用 Quickblox。我无法移植 Windows Phone 代码,所以我决定使用 RESTful API。

我在获取令牌时遇到问题。我遵循了本教程,这是我的代码:

public string Timestamp()
    {
        long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
        ticks /= 10000000;
        return ticks.ToString();
    }

    public string GetToken()
    {
        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("https://api.quickblox.com/session.xml");

        string application_id = "2675";
        string auth_key = "rGvHTKPyJJQ8PFR";
        string timestamp = Timestamp ();
        string auth_secret = "wePb4NG74eZT3eK";

        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = "application_id=" + application_id;
        postData += "&auth_key=" + auth_key;
        postData += "&timestamp=" + timestamp;

        string signature = Hash (auth_secret, postData);
        postData += "&signature=" + signature;
        byte[] data = encoding.GetBytes(postData);

        httpWReq.Method = "POST";
        httpWReq.ContentType = "application/x-www-form-urlencoded";
        httpWReq.ContentLength = data.Length;
        httpWReq.Headers ["QuickBlox-REST-API-Version"] = "0.1.0";

        using (Stream stream = httpWReq.GetRequestStream())
        {
            stream.Write(data,0,data.Length);
        }

        HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

        string responseString = new StreamReader (response.GetResponseStream()).ReadToEnd ();
        return responseString;
    }

结果,我在尝试接收时收到异常“422:无法处理的实体”httpWReq.GetResponse()

4

1 回答 1

2

您忘记添加nonce参数。

您也应该在生成签名时使用它

于 2013-05-22T19:52:44.573 回答