我在我的C#(Xamarin)应用程序中使用Quickblox。我无法移植Windows Phone代码,所以我决定使用RESTful API。
我在获取令牌时遇到问题。 我跟着this tutorial,这是我的代码:
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 += "×tamp=" + 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;
}
在结果中,我在尝试接收httpWReq.GetResponse()
答案 0 :(得分:2)
您忘记添加 nonce 参数。
此外,您应该在生成签名时使用它