使用RESTHARP - BAD请求获取HITBOX.TV获取AUTH令牌?
-
21-12-2019 - |
题
我正在尝试获得2天的Hitbox Auth令牌,但仍然只是获得相同的错误:“错误请求”以及响应内容“auth_failed”。 我在巨大的互联网上发现的只是没有帮助。:c
所以..我正在使用reastsharp,它适用于正常的HTTP URL请求(yey ...)
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);
}
.
我说的是。非常努力,但现在我最小化了代码回原始代码。
提前感谢。:)
解决方案
最后我找到了一种方法来做。它比我第一次想到的要容易得多。
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);
}
.
现在可以在响应中找到Auth令牌...
嗯,“应用程序”值缺失。所以我在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 不隶属于 StackOverflow