使用Restsharp - Bad Request从hitbox.tv获取身份验证令牌?

时间:2014-04-11 19:31:22

标签: c# authentication token restsharp bad-request

我正在尝试获得2天的hitbox身份验证令牌,但仍然只是得到相同的错误:“错误请求”和响应内容“auth_failed”。 我在巨大的互联网上找到的所有东西都没有帮助。 :C

所以..我正在使用Restsharp,它可以正常用于正常的HTTP URL请求(是的......)

hitbox的文档很短(http://developers.hitbox.tv/token)...所以没那么多帮助

(我知道这个主题存在很多问题,尝试最多,但仍然有同样的反应......)

这就是我的Code atm:

  public static void GetAuthToken(object user)
  {
       var client = new RestClient();
       client.BaseUrl = "http://api.hitbox.tv/";

       var request = new RestRequest("auth/token", Method.POST) { RequestFormat = DataFormat.Json };
       request.AddBody("login=Zetter&pass=MyPassword&app=MyAppName");

       var response = client.Execute(request);
       Console.Out.WriteLine(response.StatusDescription);
       Console.Out.WriteLine(response.Content);
  }

正如我所说。非常尝试,但是现在我将代码最小化回原始代码。

提前致谢。 :)

1 个答案:

答案 0 :(得分:1)

最后我找到了一种方法。它比我想象的容易得多。

public static void GetAuthToken(object user)
{
    var client = new RestClient();
    client.BaseUrl = "http://api.hitbox.tv";
    client.Authenticator = new SimpleAuthenticator("login", "Zetter", "pass", "MyPassword");
    var request = new RestRequest("auth/token/", Method.POST);
    var response = client.Post(request);
}

现在可以在响应中找到身份验证令牌......

" app"价值缺失。所以我研究了Restsharp的源文件并找到了这个解决方案:

public static void GetAuthToken(object user)
{
    var client = new RestClient();
    client.BaseUrl = "http://api.hitbox.tv";

    var request = new RestRequest("auth/token/", Method.POST);
    request.AddParameter("login", "Zetter");
    request.AddParameter("pass", "MyPassword");
    request.AddParameter("app", "AppName");

    var response = client.Post(request);
}

那个编码...... xD