问题描述
我想制作一个程序来检查彩带是否直播。我试图自己做,但是出了点问题。 这是代码
static HttpClientHandler hcHandle = new HttpClientHandler();
static async Task<bool> IsOnline(string channel)
{
using (var hc = new HttpClient(hcHandle,false))
{
hc.DefaultRequestHeaders.ExpectContinue = false;
hc.DefaultRequestHeaders.Add("Client-ID","xn8q3fkcx5fh6mhkffn2md4to8c9m8");
hc.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("usainsrht","oauth:c159s6yw4ok1ywu0kjkeyrucr2x1kz");
hc.Timeout = TimeSpan.FromSeconds(15);
using (var response = await hc.GetAsync($"https://api.twitch.tv/helix/streams?user_login={channel}"))
{
response.EnsureSuccessStatusCode();
string jsonString = await response.Content.ReadAsStringAsync();
var r = JsonConvert.DeserializeObject<RootObject>(jsonString);
if (!(r == default(RootObject)))
{
}
else
{
return true;
}
}
}
return false;
}
public async void pictureBox2_Click(object sender,EventArgs e)
{
bool is_valid = await IsOnline("StreamerName");
if (is_valid == false)
{
MessageBox.Show("stream is offline");
}
else
{
MessageBox.Show("stream is online");
}
}
单击图片框2时出现此错误
An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.dll but was not handled in user code
在事件标签Activated Event Time Duration Thread Exception: Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.dll ("An error occured while sending the request."). Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.dll ("An error occured while sending the request.") 3.14s [4128] <No Name>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)