C
C#2mo ago
Arsenic

✅ RestSharp

When I use this code, I get an exception, but when I use Postman, there is no problem
c#
RestClient client = new();
RestRequest request = new("https://id.twitch.tv/oauth2/token?client_id=rw5emgbykwoy28o4rd2d6qv7kjt5oj&client_secret=5k8905je0p44y5yksqc94mfx6spdh0&grant_type=client_credentials");
RestResponse response = await client.PostAsync(request);
c#
RestClient client = new();
RestRequest request = new("https://id.twitch.tv/oauth2/token?client_id=rw5emgbykwoy28o4rd2d6qv7kjt5oj&client_secret=5k8905je0p44y5yksqc94mfx6spdh0&grant_type=client_credentials");
RestResponse response = await client.PostAsync(request);
No description
20 Replies
Arsenic
Arsenic2mo ago
exception:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (id.twitch.tv:443)
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (id.twitch.tv:443)
Arsenic
Arsenic2mo ago
No description
leowest
leowest2mo ago
check the headers
Arsenic
Arsenic2mo ago
and?
No description
canton7
canton72mo ago
Compare those against the headers sent by postman
leowest
leowest2mo ago
what if u do
var client = new HttpClient();
var response = await client.PostAsync("url_here", null);
var result = await response.Content.ReadFromJsonAsync<Token>();
response.EnsureSuccessStatusCode();
Console.WriteLine(result);
var client = new HttpClient();
var response = await client.PostAsync("url_here", null);
var result = await response.Content.ReadFromJsonAsync<Token>();
response.EnsureSuccessStatusCode();
Console.WriteLine(result);
Token is
public class Token
{
[JsonPropertyName("access_token")]
public required string AccessToken { get; set; }

[JsonPropertyName("expires_in")]
public int ExpiresIn { get; set; }

[JsonPropertyName("token_type")]
public required string TokenType { get; set; }

public override string ToString()
{
return $"{AccessToken}, {ExpiresIn}, {TokenType}";
}
}
public class Token
{
[JsonPropertyName("access_token")]
public required string AccessToken { get; set; }

[JsonPropertyName("expires_in")]
public int ExpiresIn { get; set; }

[JsonPropertyName("token_type")]
public required string TokenType { get; set; }

public override string ToString()
{
return $"{AccessToken}, {ExpiresIn}, {TokenType}";
}
}
canton7
canton72mo ago
⚠️ Also, you probably didn't want to post your client secret here
Somgör from Human Resources
You probably need to reset half your application creds :SCgetoutofmyhead:
leowest
leowest2mo ago
yeah dont post your secret and reset it to get new ones
Arsenic
Arsenic2mo ago
:3PorangDisappointed:
leowest
leowest2mo ago
@Arsenic I've upated the above code and tested with my own key and worked just fine. There should be no point in using RestClient over HttpClient these days.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest2mo ago
probably not, it was more to symbolize it can fail at getasync and also at Content
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Arsenic
Arsenic2mo ago
@leowest I still have a problem
No description
leowest
leowest2mo ago
so ur getting a timeout looks like your ip could have been blocked do u have a different ip u could try from? or vps, or proxy because I tried myself with that very same code and it all went thru.
Arsenic
Arsenic2mo ago
Yes, I have a VPS. I also tested it with JavaScript, there was no problem and it worked well, but it seems that C# is not going to be OK
leowest
leowest2mo ago
so maybe your firewall is blocking the c# app or antivirus try it from a vps
Arsenic
Arsenic2mo ago
solved now ty
MODiX
MODiX2mo ago
If you have no further questions, please use /close to mark the forum thread as answered