【问题标题】:Getting auth token from hitbox.tv with Restsharp - Bad Request?使用 Restsharp 从 hitbox.tv 获取身份验证令牌 - 错误请求?
【发布时间】:2014-04-11 19:31:22
【问题描述】:

我正在尝试获取一个 hitbox 身份验证令牌 2 天,但仍然收到相同的错误:“错误请求”和响应内容“auth_failed”。 我在庞大的互联网上找到的一切都无济于事。 :C

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

hitbox 的文档很短 (http://developers.hitbox.tv/token) ... 所以帮助不大

(我知道这个话题有很多问题,尝试了最多,但仍然是相同的反应......)

这就是我的代码 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);
  }

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

提前致谢。 :)

【问题讨论】:

    标签: c# authentication token restsharp bad-request


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2018-11-12
      • 2016-04-04
      • 2020-08-18
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多