远程服务器 returns 404 未找到错误 c#
Remote Server returns 404 not found error c#
我正在创建一个检查用户状态的应用程序。我收到 404 未找到错误。任何人都可以在下面发布帮助代码。我做错了什么?
static void Main(string[] args)
{
var Usernames = File.ReadAllLines(@"C:\Users\Hasan\Desktop\Usernames.txt");
Parallel.ForEach(Usernames, Username =>
{
try
{
using (WebClient WebClient = new WebClient())
{
WebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
if(response.Contains("not - found"))
{
Console.WriteLine("Possibly Free : " + Username);
}
}
}
catch (Exception ex)
{
//Console.WriteLine("Error on Username : " + Username);
Console.WriteLine(ex.Message);
Console.ReadLine();
}
});
}
因为某些原因你的用户名是空白的&
您的 DownloadString 变为
因此出现 404 错误..
尝试在这一行放置调试器
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
您将看到一个空白的用户名..
因为 .. 我检查了 Api 对于像
这样的有效用户名在其他方面工作正常
并返回一个有效的 JSON
{"uniqueId":"hhus-04bce17a17b59979fbd97aa46110a650","name":"Trump","figureString":"hr-835-1402.hd-627-13.ch-3005-1326-97.lg-3483-1415-1415.he-3227-95.fa-3276-1328","motto":"covfefe","memberSince":"2011-05-11T22:20:28.000+0000","profileVisible":true,"selectedBadges":[{"badgeIndex":1,"code":"ACH_RegistrationDuration20","name":"100 % True Habbo XX","description":"Be a member of the community for 1825 days."},{"badgeIndex":2,"code":"UK824","name":"You took a quack at the duck games! (And won!)","description":""},{"badgeIndex":3,"code":"UK833","name":"Singapores National Flower","description":""},{"badgeIndex":4,"code":"UK835","name":"I picked a Lignum Vitae on Jamaica Day 2017!","description":""},{"badgeIndex":5,"code":"UK838","name":"Pretty Polly want a cracker?!","description":""}]}
网络 API returns 每个未知用户的 404 错误。在 404 响应中,网络客户端抛出异常,因此您需要将验证调整为如下所示:
static void Main(string[] args)
{
var Usernames = File.ReadAllLines(@"C:\Users\Hasan\Desktop\Usernames.txt");
Parallel.ForEach(Usernames, Username =>
{
try
{
using (WebClient WebClient = new WebClient())
{
WebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
}
catch (Exception ex)
{
if ( ex is WebException and (ex.Response as HttpWebResponse)?.StatusCode.ToString() ?? ex.Status.ToString() == "404" )
{
Console.WriteLine("Possibly Free : " + Username);
}
//Console.WriteLine("Error on Username : " + Username);
Console.WriteLine(ex.Message);
Console.ReadLine();
}
});
}
我正在创建一个检查用户状态的应用程序。我收到 404 未找到错误。任何人都可以在下面发布帮助代码。我做错了什么?
static void Main(string[] args)
{
var Usernames = File.ReadAllLines(@"C:\Users\Hasan\Desktop\Usernames.txt");
Parallel.ForEach(Usernames, Username =>
{
try
{
using (WebClient WebClient = new WebClient())
{
WebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
if(response.Contains("not - found"))
{
Console.WriteLine("Possibly Free : " + Username);
}
}
}
catch (Exception ex)
{
//Console.WriteLine("Error on Username : " + Username);
Console.WriteLine(ex.Message);
Console.ReadLine();
}
});
}
因为某些原因你的用户名是空白的&
您的 DownloadString 变为
因此出现 404 错误..
尝试在这一行放置调试器
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
您将看到一个空白的用户名..
因为 .. 我检查了 Api 对于像
这样的有效用户名在其他方面工作正常并返回一个有效的 JSON
{"uniqueId":"hhus-04bce17a17b59979fbd97aa46110a650","name":"Trump","figureString":"hr-835-1402.hd-627-13.ch-3005-1326-97.lg-3483-1415-1415.he-3227-95.fa-3276-1328","motto":"covfefe","memberSince":"2011-05-11T22:20:28.000+0000","profileVisible":true,"selectedBadges":[{"badgeIndex":1,"code":"ACH_RegistrationDuration20","name":"100 % True Habbo XX","description":"Be a member of the community for 1825 days."},{"badgeIndex":2,"code":"UK824","name":"You took a quack at the duck games! (And won!)","description":""},{"badgeIndex":3,"code":"UK833","name":"Singapores National Flower","description":""},{"badgeIndex":4,"code":"UK835","name":"I picked a Lignum Vitae on Jamaica Day 2017!","description":""},{"badgeIndex":5,"code":"UK838","name":"Pretty Polly want a cracker?!","description":""}]}
网络 API returns 每个未知用户的 404 错误。在 404 响应中,网络客户端抛出异常,因此您需要将验证调整为如下所示:
static void Main(string[] args)
{
var Usernames = File.ReadAllLines(@"C:\Users\Hasan\Desktop\Usernames.txt");
Parallel.ForEach(Usernames, Username =>
{
try
{
using (WebClient WebClient = new WebClient())
{
WebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
string response = WebClient.DownloadString("https://www.habbo.com/api/public/users?name=" + Username);
}
catch (Exception ex)
{
if ( ex is WebException and (ex.Response as HttpWebResponse)?.StatusCode.ToString() ?? ex.Status.ToString() == "404" )
{
Console.WriteLine("Possibly Free : " + Username);
}
//Console.WriteLine("Error on Username : " + Username);
Console.WriteLine(ex.Message);
Console.ReadLine();
}
});
}